From 5ef15bfb902512a4042e3665636fc357395c82f9 Mon Sep 17 00:00:00 2001 From: cloudinary-pkoniu Date: Tue, 11 Feb 2025 16:07:32 +0100 Subject: [PATCH 1/5] feat: allow deleting resources by asset_ids --- lib/api.js | 6 ++++++ test/integration/api/admin/api_spec.js | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/api.js b/lib/api.js index 5e5fdfe7..f6234245 100644 --- a/lib/api.js +++ b/lib/api.js @@ -150,6 +150,12 @@ exports.delete_resources = function delete_resources(public_ids, callback, optio }), callback, options); }; +exports.delete_resources_by_asset_ids = function delete_resources_by_asset_ids(asset_ids, callback, options = {}) { + return call_api("delete", "resources", deleteResourcesParams(options, { + "asset_ids[]": asset_ids + }), callback, options); +}; + exports.delete_resources_by_prefix = function delete_resources_by_prefix(prefix, callback, options = {}) { let resource_type, type, uri; resource_type = options.resource_type || "image"; diff --git a/test/integration/api/admin/api_spec.js b/test/integration/api/admin/api_spec.js index 227026c1..3bdf2f47 100644 --- a/test/integration/api/admin/api_spec.js +++ b/test/integration/api/admin/api_spec.js @@ -582,6 +582,26 @@ describe("api", function () { expect(error.http_code).to.eql(404); }); }); + it.only("should allow deleting resources by asset_ids", function () { + this.timeout(TIMEOUT.MEDIUM); + return uploadImage({ + public_id: PUBLIC_ID_3, + tags: UPLOAD_TAGS + }).then( + () => cloudinary.v2.api.resource(PUBLIC_ID_3) + ).then(function (resource) { + expect(resource).not.to.eql(void 0); + console.log(resource); + return cloudinary.v2.api.delete_resources_by_asset_ids([resource.asset_id]); + }).then( + () => cloudinary.v2.api.resource(PUBLIC_ID_3) + ).then(() => { + expect().fail(); + }).catch(function ({error}) { + expect(error).to.be.an(Object); + expect(error.http_code).to.eql(404); + }); + }); describe("delete_resources_by_prefix", function () { callReusableTest("accepts next_cursor", cloudinary.v2.api.delete_resources_by_prefix, "prefix_foobar"); return it("should allow deleting resources by prefix", function () { From 8d8a03cbebe0a4912b283c5f12f7a4752958879a Mon Sep 17 00:00:00 2001 From: Tia Esguerra Date: Thu, 25 Sep 2025 14:22:49 -0700 Subject: [PATCH 2/5] add URI array --- lib/api.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/api.js b/lib/api.js index 6b227718..83f05a2b 100644 --- a/lib/api.js +++ b/lib/api.js @@ -151,7 +151,8 @@ exports.delete_resources = function delete_resources(public_ids, callback, optio }; exports.delete_resources_by_asset_ids = function delete_resources_by_asset_ids(asset_ids, callback, options = {}) { - return call_api("delete", "resources", deleteResourcesParams(options, { + let uri = ["resources"] + return call_api("delete", uri, deleteResourcesParams(options, { "asset_ids[]": asset_ids }), callback, options); }; From 1d4cf1ce6845000bef77dc3191fb3c41df8302a0 Mon Sep 17 00:00:00 2001 From: Tia Esguerra Date: Thu, 25 Sep 2025 14:23:36 -0700 Subject: [PATCH 3/5] add function to the list of v2 adapters --- lib/v2/api.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/v2/api.js b/lib/v2/api.js index 4f109841..9da8b28b 100644 --- a/lib/v2/api.js +++ b/lib/v2/api.js @@ -17,6 +17,7 @@ v1_adapters(exports, api, { restore: 1, update: 1, delete_resources: 1, + delete_resources_by_asset_ids: 1, delete_resources_by_prefix: 1, delete_resources_by_tag: 1, delete_all_resources: 0, From d30ab260040cd181418706e4bba6e701df1a65cc Mon Sep 17 00:00:00 2001 From: Tia Esguerra Date: Thu, 25 Sep 2025 14:24:28 -0700 Subject: [PATCH 4/5] add the typescript functions --- types/index.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/index.d.ts b/types/index.d.ts index 20378969..58a8757e 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1011,6 +1011,10 @@ declare module 'cloudinary' { function delete_resources(value: string[], options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; + function delete_resources_by_asset_ids(asset_ids: string[], callback?: ResponseCallback): Promise; + + function delete_resources_by_asset_ids(asset_ids: string[], options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; + function delete_resources_by_prefix(prefix: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise; function delete_resources_by_prefix(prefix: string, callback?: ResponseCallback): Promise; From 9a00749a70e7cbb4f1e7c412faf67a87788bc57f Mon Sep 17 00:00:00 2001 From: Tia Esguerra Date: Thu, 25 Sep 2025 14:25:27 -0700 Subject: [PATCH 5/5] remove .only --- test/integration/api/admin/api_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/api/admin/api_spec.js b/test/integration/api/admin/api_spec.js index cb45001a..c7df5a62 100644 --- a/test/integration/api/admin/api_spec.js +++ b/test/integration/api/admin/api_spec.js @@ -582,7 +582,7 @@ describe("api", function () { expect(error.http_code).to.eql(404); }); }); - it.only("should allow deleting resources by asset_ids", function () { + it("should allow deleting resources by asset_ids", function () { this.timeout(TIMEOUT.MEDIUM); return uploadImage({ public_id: PUBLIC_ID_3,