Skip to content

Commit 8335bd9

Browse files
authored
Cloudinary usability improvements (#15091)
* Cloudinary package update * Get Account Usage improvements and error handling * Get Resources improvements & error handling * Upload Media reworked and simplified * File upload improvements * Reworking image transformation * Video transformation + version bumps * ESLint fixes * pnpm * Improvements to transformation options * Removing 'transform image' in favor of 'transform resource'
1 parent 85abca8 commit 8335bd9

File tree

15 files changed

+218
-413
lines changed

15 files changed

+218
-413
lines changed

components/acronis_cyber_protect_cloud/acronis_cyber_protect_cloud.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/bitdefender_gravityzone/bitdefender_gravityzone.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/cloudinary/actions/get-account-usage-details/get-account-usage-details.mjs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ import cloudinary from "../../cloudinary.app.mjs";
33
export default {
44
key: "cloudinary-get-account-usage-details",
55
name: "Get Account Usage Details",
6-
description: "Enables you to get a report on the status of your Cloudinary account usage details, including storage, credits, bandwidth, requests, number of resources, and add-on usage. [See the documentation](https://cloudinary.com/documentation/admin_api#usage)",
7-
version: "0.1.2",
6+
description: "Gets a report of your Cloudinary account usage details, including storage, credits, bandwidth, requests, number of resources, and add-on usage. [See the documentation](https://cloudinary.com/documentation/admin_api#usage)",
7+
version: "0.2.0",
88
type: "action",
99
props: {
1010
cloudinary,
11+
dateInfo: {
12+
type: "alert",
13+
alertType: "info",
14+
content: "If `Date` is not specified, it defaults to the current date.",
15+
},
1116
date: {
1217
type: "string",
1318
label: "Date",
14-
description: "The date for the usage report. Must be within the last 3 months and given in the format: `dd-mm-yyyy`. Default: the current date",
19+
description: "The date for the usage report, in the `yyyy-mm-dd` format, e.g. `2019-07-21`. Must be between yesterday and the last 3 months.",
1520
optional: true,
1621
},
1722
},
@@ -20,12 +25,17 @@ export default {
2025
date: this.date,
2126
};
2227

23-
const response = await this.cloudinary.getUsage(options);
28+
try {
29+
const response = await this.cloudinary.getUsage(options);
2430

25-
if (response) {
26-
$.export("$summary", "Successfully retrieved usage details.");
27-
}
31+
if (response) {
32+
$.export("$summary", "Successfully retrieved usage details");
33+
}
2834

29-
return response;
35+
return response;
36+
}
37+
catch (err) {
38+
throw new Error(`Cloudinary error response: ${err.error?.message ?? JSON.stringify(err)}`);
39+
}
3040
},
3141
};

components/cloudinary/actions/get-resources/get-resources.mjs

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "cloudinary-get-resources",
55
name: "Get Resources",
66
description: "Lists resources (assets) uploaded to your product environment. [See the documentation](https://cloudinary.com/documentation/admin_api#get_resources)",
7-
version: "0.0.1",
7+
version: "0.1.0",
88
type: "action",
99
props: {
1010
cloudinary,
@@ -22,28 +22,35 @@ export default {
2222
},
2323
prefix: {
2424
type: "string",
25-
label: "Prefix",
26-
description: "Find all assets with a public ID that starts with the specified prefix",
25+
label: "Filter by Prefix",
26+
description: "Find all assets with a public ID that starts with the specified prefix.",
2727
optional: true,
2828
},
2929
tags: {
3030
type: "boolean",
31-
label: "Tags",
32-
description: "Whether to include the list of tag names assigned to each asset",
31+
label: "Include Tags",
32+
description: "Whether to include the list of tag names assigned to each asset.",
3333
default: false,
3434
optional: true,
3535
},
3636
context: {
3737
type: "boolean",
38-
label: "Context",
39-
description: "Whether to include key-value pairs of contextual metadata associated with each asset",
38+
label: "Include Context",
39+
description: "Whether to include key-value pairs of contextual metadata associated with each asset.",
40+
default: false,
41+
optional: true,
42+
},
43+
metadata: {
44+
type: "boolean",
45+
label: "Include Metadata",
46+
description: "Whether to include the structured metadata fields and values assigned to each asset.",
4047
default: false,
4148
optional: true,
4249
},
4350
moderation: {
4451
type: "boolean",
45-
label: "Moderation",
46-
description: "Whether to include the image moderation status of each asset",
52+
label: "Include Moderation",
53+
description: "Whether to include the image moderation status of each asset.",
4754
default: false,
4855
optional: true,
4956
},
@@ -66,22 +73,27 @@ export default {
6673
};
6774

6875
const resources = [];
69-
let next;
70-
do {
71-
const response = await this.cloudinary.getResources(options);
72-
resources.push(...response.resources);
73-
next = response.next_cursor;
74-
options.next_cursor = next;
75-
} while (next && resources.length < this.maxResults);
76+
try {
77+
let next;
78+
do {
79+
const response = await this.cloudinary.getResources(options);
80+
resources.push(...response.resources);
81+
next = response.next_cursor;
82+
options.next_cursor = next;
83+
} while (next && resources.length < this.maxResults);
7684

77-
if (resources.length > this.maxResults) {
78-
resources.length = this.maxResults;
79-
}
85+
if (resources.length > this.maxResults) {
86+
resources.length = this.maxResults;
87+
}
8088

81-
$.export("$summary", `Found ${resources.length} resource${resources.length === 1
82-
? ""
83-
: "s"}.`);
89+
$.export("$summary", `Retrieved ${resources.length} resource${resources.length === 1
90+
? ""
91+
: "s"}`);
8492

85-
return resources;
93+
return resources;
94+
}
95+
catch (err) {
96+
throw new Error(`Cloudinary error response: ${err.error?.message ?? JSON.stringify(err)}`);
97+
}
8698
},
8799
};

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

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 0 additions & 46 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+
};

0 commit comments

Comments
 (0)