Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import cloudinary from "../../cloudinary.app.mjs";
export default {
key: "cloudinary-get-account-usage-details",
name: "Get Account Usage Details",
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)",
version: "0.1.2",
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)",
version: "0.2.0",
type: "action",
props: {
cloudinary,
dateInfo: {
type: "alert",
alertType: "info",
content: "If `Date` is not specified, it defaults to the current date.",
},
date: {
type: "string",
label: "Date",
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",
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.",
optional: true,
},
},
Expand All @@ -20,12 +25,17 @@ export default {
date: this.date,
};

const response = await this.cloudinary.getUsage(options);
try {
const response = await this.cloudinary.getUsage(options);

if (response) {
$.export("$summary", "Successfully retrieved usage details.");
}
if (response) {
$.export("$summary", "Successfully retrieved usage details");
}

return response;
return response;
}
catch (err) {
throw new Error(`Cloudinary error response: ${err.error?.message ?? JSON.stringify(err)}`);
}
},
};
58 changes: 35 additions & 23 deletions components/cloudinary/actions/get-resources/get-resources.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "cloudinary-get-resources",
name: "Get Resources",
description: "Lists resources (assets) uploaded to your product environment. [See the documentation](https://cloudinary.com/documentation/admin_api#get_resources)",
version: "0.0.1",
version: "0.1.0",
type: "action",
props: {
cloudinary,
Expand All @@ -22,28 +22,35 @@ export default {
},
prefix: {
type: "string",
label: "Prefix",
description: "Find all assets with a public ID that starts with the specified prefix",
label: "Filter by Prefix",
description: "Find all assets with a public ID that starts with the specified prefix.",
optional: true,
},
tags: {
type: "boolean",
label: "Tags",
description: "Whether to include the list of tag names assigned to each asset",
label: "Include Tags",
description: "Whether to include the list of tag names assigned to each asset.",
default: false,
optional: true,
},
context: {
type: "boolean",
label: "Context",
description: "Whether to include key-value pairs of contextual metadata associated with each asset",
label: "Include Context",
description: "Whether to include key-value pairs of contextual metadata associated with each asset.",
default: false,
optional: true,
},
metadata: {
type: "boolean",
label: "Include Metadata",
description: "Whether to include the structured metadata fields and values assigned to each asset.",
default: false,
optional: true,
},
Comment on lines +43 to 49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

🛠️ Refactor suggestion

Add metadata property to options object

The review comment is correct. The metadata property is defined in the component's props but not included in the options object passed to the Cloudinary API call. Here are the specific locations that need attention:

  • In components/cloudinary/actions/get-resources/get-resources.mjs, add the metadata property to the options object in the run method:
const options = {
  resource_type: this.resourceType,
  type: this.type,
  prefix: this.prefix,
  tags: this.tags,
  context: this.context,
  moderation: this.moderation,
  metadata: this.metadata,
};
🔗 Analysis chain

Verify metadata property integration with Cloudinary API

The new metadata property is well-documented, but it needs to be included in the options object passed to the Cloudinary API.

Add the metadata property to the options object in the run method:

    const options = {
      resource_type: this.resourceType,
      type: this.type,
      prefix: this.prefix,
      tags: this.tags,
      context: this.context,
      moderation: this.moderation,
+     metadata: this.metadata,
    };

Let me verify if the metadata property is properly integrated with the Cloudinary API by checking the implementation.


Let me fix the regex and try again.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Check the implementation of the run method in the get-resources component
rg -A 20 "run\s*\(\s*\)\s*{" components/cloudinary/actions/get-resources/get-resources.mjs

Length of output: 190


Script:

#!/bin/bash
# Check the implementation of the run method in the get-resources component
rg "async run" -A 20 components/cloudinary/actions/get-resources/get-resources.mjs

Length of output: 674

moderation: {
type: "boolean",
label: "Moderation",
description: "Whether to include the image moderation status of each asset",
label: "Include Moderation",
description: "Whether to include the image moderation status of each asset.",
default: false,
optional: true,
},
Expand All @@ -66,22 +73,27 @@ export default {
};

const resources = [];
let next;
do {
const response = await this.cloudinary.getResources(options);
resources.push(...response.resources);
next = response.next_cursor;
options.next_cursor = next;
} while (next && resources.length < this.maxResults);
try {
let next;
do {
const response = await this.cloudinary.getResources(options);
resources.push(...response.resources);
next = response.next_cursor;
options.next_cursor = next;
} while (next && resources.length < this.maxResults);

if (resources.length > this.maxResults) {
resources.length = this.maxResults;
}
if (resources.length > this.maxResults) {
resources.length = this.maxResults;
}

$.export("$summary", `Found ${resources.length} resource${resources.length === 1
? ""
: "s"}.`);
$.export("$summary", `Retrieved ${resources.length} resource${resources.length === 1
? ""
: "s"}`);

return resources;
return resources;
}
catch (err) {
throw new Error(`Cloudinary error response: ${err.error?.message ?? JSON.stringify(err)}`);
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,68 @@ import cloudinary from "../../cloudinary.app.mjs";

export default {
key: "cloudinary-image-transformation",
name: "Image Transformation",
description: "Transforms images on-the-fly. It modifies them to any required format, style and dimension, resize and crop the images, etc. [See the documentation](https://cloudinary.com/documentation/image_transformations)",
version: "0.1.2",
name: "Transform Image",
description: "Transform an image asset on-the-fly with several options. [See the documentation](https://cloudinary.com/documentation/image_transformations)",
version: "0.1.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version: "0.1.0",
version: "0.2.0",

type: "action",
props: {
cloudinary,
imageSource: {
assetId: {
propDefinition: [
cloudinary,
"assetId",
],
},
width: {
type: "integer",
label: "Width",
description: "The new width of the image, e.g. `300`",
optional: true,
},
height: {
type: "integer",
label: "Height",
description: "The new height of the image, e.g. `300`",
optional: true,
},
background: {
type: "string",
label: "Public ID",
description: "The [public ID](https://cloudinary.com/documentation/upload_images#public_id) that references a file you've previously uploaded to Cloudinary, e.g. `folder/filename`.",
label: "Background",
description: "The background color to apply on transparent areas of the image, as a named color or RGB(A) value, e.g. `blue` or `8B0`",
optional: true,
},
options: {
type: "object",
label: "Options",
description: "The image transformation options to apply and/or the URL parameters supported by Cloudinary API. For all transformation options, please check [Image transformation API reference](https://cloudinary.com/documentation/image_transformation_reference), for URL parameters, please check [Transforming media assets using dynamic URLs](https://cloudinary.com/documentation/image_transformations#transforming_media_assets_using_dynamic_urls)",
opacity: {
type: "integer",
label: "Opacity",
description: "The opacity level to set for the image, from 0 to 100",
optional: true,
min: 0,
max: 100,
},
transformations: {
propDefinition: [
cloudinary,
"transformations",
],
},
},
async run({ $ }) {
const response = await this.cloudinary.transformImage(this.imageSource, this.options);
const {
cloudinary, assetId, transformations, ...options
} = this;
try {
const response = await cloudinary.transformAsset(assetId, {
...options,
...transformations,
});

if (response) {
$.export("$summary", "Successfully transformed image.");
}
if (response) {
$.export("$summary", "Successfully transformed image");
}

return response;
return response;
} catch (err) {
throw new Error(`Cloudinary error response: ${err.error?.message ?? JSON.stringify(err)}`);
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,60 @@ import cloudinary from "../../cloudinary.app.mjs";

export default {
key: "cloudinary-resource-transformation",
name: "Resource Transformation",
description: "Transforms image or video resources on-the-fly. It allows transformation options for resource optimization (i.e. web viewing), resize and crop the resources, etc. [Image transformation documentation](https://cloudinary.com/documentation/image_transformations). [Video transformation documentation](https://cloudinary.com/documentation/video_transformation_reference)",
version: "0.2.2",
name: "Transform Video or Audio",
description: "Transform a video or audio asset on-the-fly with several options. [See the documentation](https://cloudinary.com/documentation/video_manipulation_and_delivery)",
version: "0.3.0",
type: "action",
props: {
cloudinary,
resourceType: {
assetId: {
propDefinition: [
cloudinary,
"transformationResourceType",
"assetId",
],
},
options: {
type: "string",
label: "Options",
description: "For an image `resourceType`, use this parameter to set the image transformation options to apply and/or the URL parameters supported by Cloudinary API. For all transformation options, please check [Image transformation API reference](https://cloudinary.com/documentation/image_transformation_reference), for URL parameters, please check [Transforming media assets using dynamic URLs](https://cloudinary.com/documentation/image_transformations#transforming_media_assets_using_dynamic_urls).\nFor a video `resourceType`, use this parameter to set video transformation options to apply and/or the URL parameters supported by Cloudinary API. For all transformation options, please check [Video transformation API reference](https://cloudinary.com/documentation/video_transformation_reference), for URL parameters, please check [Transforming media assets using dynamic URLs](https://cloudinary.com/documentation/image_transformations#transforming_media_assets_using_dynamic_urls).",
width: {
type: "integer",
label: "Width",
description: "The new width of the video, e.g. `854`",
optional: true,
},
imageSource: {
type: "string",
label: "Image Source",
description: "If `resourceType` is an image, use this parameter to point to the source of the image to apply transformations on. It can be a local file, the actual image data, a remote FTP, HTTP or HTTPS URL address of an existing image. For details and examples, see: [file source options](https://cloudinary.com/documentation/upload_images#file_source_options).",
height: {
type: "integer",
label: "Height",
description: "The new height of the video, e.g. `480`",
optional: true,
},
videoPublicId: {
type: "string",
label: "Video Public Id",
description: "If `resourceType` is a video, use this parameter to set the public id of the video to apply transformations on. The public id is the unique identifier of the video, and is either specified when uploading the video to your Cloudinary account, or automatically assigned by Cloudinary. For more details on the options for specifying the public id, see [Public ID - the image identifier](https://cloudinary.com/documentation/upload_images#public_id).",
duration: {
type: "integer",
label: "Duration",
description: "The duration to set for the video in seconds, e.g. `30`",
optional: true,
},
transformations: {
propDefinition: [
cloudinary,
"transformations",
],
},
},
async run({ $ }) {
const response = this.resourceType === "image"
? await this.cloudinary.transformImage(this.imageSource, this.options)
: await this.cloudinary.transformVideo(this.videoPublicId, this.options);
const {
cloudinary, assetId, transformations, ...options
} = this;
try {
const response = await cloudinary.transformAsset(assetId, {
...options,
...transformations,
});

if (response) {
$.export("$summary", `Successfully transformed ${this.resourceType}`);
}
if (response) {
$.export("$summary", "Successfully transformed video");
}

return response;
return response;
} catch (err) {
throw new Error(`Cloudinary error response: ${err.error?.message ?? JSON.stringify(err)}`);
}
},
};
Loading
Loading