Skip to content

Commit 7b01566

Browse files
committed
Improvements to transformation options
1 parent 57a81ee commit 7b01566

File tree

3 files changed

+93
-61
lines changed

3 files changed

+93
-61
lines changed

components/cloudinary/actions/resource-transformation/resource-transformation.mjs

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import cloudinary from "../../cloudinary.app.mjs";
3+
4+
export default {
5+
key: "cloudinary-transform-resource",
6+
name: "Transform Resource",
7+
description: "Transform an image, video or audio asset on-the-fly with several options. [See the documentation](https://cloudinary.com/documentation/video_manipulation_and_delivery)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
cloudinary,
12+
assetId: {
13+
propDefinition: [
14+
cloudinary,
15+
"assetId",
16+
],
17+
},
18+
info: {
19+
type: "alert",
20+
alertType: "info",
21+
content: `You can either select a pre-configured transformation or pass a transformation string. Both can be managed in the [Cloudinary Transformation Builder](https://tx.cloudinary.com/).
22+
\\
23+
If both are specified, the transformation string will be ignored.`,
24+
},
25+
namedTransformation: {
26+
propDefinition: [
27+
cloudinary,
28+
"namedTransformation",
29+
],
30+
},
31+
transformationString: {
32+
propDefinition: [
33+
cloudinary,
34+
"transformationString",
35+
],
36+
},
37+
},
38+
async run({ $ }) {
39+
const {
40+
cloudinary, assetId, namedTransformation, transformationString,
41+
} = this;
42+
43+
if (!namedTransformation && !transformationString) {
44+
throw new ConfigurationError("Either `Named Transformation` or `Transformation String` are required");
45+
}
46+
47+
try {
48+
const response = await cloudinary.transformAsset(assetId, namedTransformation
49+
? {
50+
transformation: namedTransformation,
51+
}
52+
: {
53+
raw_transformation: transformationString,
54+
});
55+
56+
if (response) {
57+
$.export("$summary", "Successfully transformed resource");
58+
}
59+
60+
return response;
61+
} catch (err) {
62+
throw new Error(`Cloudinary error response: ${err.error?.message ?? JSON.stringify(err)}`);
63+
}
64+
},
65+
};

components/cloudinary/cloudinary.app.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,31 @@ export default {
6262
label: "Additional Transformations",
6363
description: "Additional transformations to apply to the resource. [See the documentation](https://cloudinary.com/documentation/transformation_reference) for all available transformations. Example: `{ \"angle\": 90, \"color_space\": \"srgb\"}`",
6464
},
65+
transformationString: {
66+
type: "string",
67+
label: "Transformation String",
68+
description: "A string representing the transformation to apply to the resource. You can use the [Cloudinary Transformation Builder](https://tx.cloudinary.com/) to create and preview the transformation, then copy the string here. Example: `c_fill,h_500,w_500` is the transformation string in the URL `https://res.cloudinary.com/demo/video/upload/c_fill,h_500,w_500/samples/cld-sample-video.mp4`",
69+
optional: true,
70+
},
71+
namedTransformation: {
72+
type: "string",
73+
label: "Named Transformation",
74+
description: "Select a pre-configured named transformation to apply to the resource. You can create and manage transformations in the [Cloudinary Transformation Builder](https://tx.cloudinary.com).",
75+
optional: true,
76+
async options({ prevContext: { cursor } }) {
77+
const {
78+
transformations, next_cursor,
79+
} = await this.getTransformations({
80+
next_cursor: cursor,
81+
});
82+
return {
83+
options: transformations?.filter?.((t) => t.named).map((t) => t.name.replace(/^t_/, "")),
84+
context: {
85+
cursor: next_cursor,
86+
},
87+
};
88+
},
89+
},
6590
},
6691
methods: {
6792
_client() {
@@ -85,5 +110,8 @@ export default {
85110
async uploadMedia(file, options) {
86111
return this._client().uploader.upload(file, options);
87112
},
113+
async getTransformations(args) {
114+
return this._client().api.transformations(args);
115+
},
88116
},
89117
};

0 commit comments

Comments
 (0)