diff --git a/lib/api.js b/lib/api.js index f5a598d8..83f05a2b 100644 --- a/lib/api.js +++ b/lib/api.js @@ -150,6 +150,13 @@ 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 = {}) { + let uri = ["resources"] + return call_api("delete", uri, 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/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, diff --git a/test/integration/api/admin/api_spec.js b/test/integration/api/admin/api_spec.js index d63aa92b..c7df5a62 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("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 () { 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;