Skip to content

Commit 13b8822

Browse files
committed
Get Resources improvements & error handling
1 parent 531d3d9 commit 13b8822

File tree

3 files changed

+46
-34
lines changed

3 files changed

+46
-34
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111
dateInfo: {
1212
type: "alert",
1313
alertType: "info",
14-
content: "If `Date` is not specified, it defaults to the current date."
14+
content: "If `Date` is not specified, it defaults to the current date.",
1515
},
1616
date: {
1717
type: "string",
@@ -26,16 +26,16 @@ export default {
2626
};
2727

2828
try {
29-
const response = await this.cloudinary.getUsage(options);
29+
const response = await this.cloudinary.getUsage(options);
3030

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

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

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.{{ts}}",
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/cloudinary.app.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
resourceType: {
99
type: "string",
1010
label: "Resource Type",
11-
description: "The type of asset. Defaults to `image` if left blank",
11+
description: "The type of asset. Defaults to `image` if not specified. `Note:` use video for all video and audio assets, such as `.mp3`. ",
1212
options: constants.RESOURCE_TYPE_OPTIONS,
1313
default: "image",
1414
optional: true,
@@ -32,7 +32,7 @@ export default {
3232
deliveryType: {
3333
type: "string",
3434
label: "Type",
35-
description: "The delivery type. Defaults to `upload` if left blank",
35+
description: "The delivery type. Defaults to `upload` if not specified.",
3636
options: constants.DELIVERY_TYPE_OPTIONS,
3737
default: "upload",
3838
optional: true,

0 commit comments

Comments
 (0)