Skip to content

Commit 5ef15bf

Browse files
feat: allow deleting resources by asset_ids
1 parent d12a63f commit 5ef15bf

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/api.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ exports.delete_resources = function delete_resources(public_ids, callback, optio
150150
}), callback, options);
151151
};
152152

153+
exports.delete_resources_by_asset_ids = function delete_resources_by_asset_ids(asset_ids, callback, options = {}) {
154+
return call_api("delete", "resources", deleteResourcesParams(options, {
155+
"asset_ids[]": asset_ids
156+
}), callback, options);
157+
};
158+
153159
exports.delete_resources_by_prefix = function delete_resources_by_prefix(prefix, callback, options = {}) {
154160
let resource_type, type, uri;
155161
resource_type = options.resource_type || "image";

test/integration/api/admin/api_spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,26 @@ describe("api", function () {
582582
expect(error.http_code).to.eql(404);
583583
});
584584
});
585+
it.only("should allow deleting resources by asset_ids", function () {
586+
this.timeout(TIMEOUT.MEDIUM);
587+
return uploadImage({
588+
public_id: PUBLIC_ID_3,
589+
tags: UPLOAD_TAGS
590+
}).then(
591+
() => cloudinary.v2.api.resource(PUBLIC_ID_3)
592+
).then(function (resource) {
593+
expect(resource).not.to.eql(void 0);
594+
console.log(resource);
595+
return cloudinary.v2.api.delete_resources_by_asset_ids([resource.asset_id]);
596+
}).then(
597+
() => cloudinary.v2.api.resource(PUBLIC_ID_3)
598+
).then(() => {
599+
expect().fail();
600+
}).catch(function ({error}) {
601+
expect(error).to.be.an(Object);
602+
expect(error.http_code).to.eql(404);
603+
});
604+
});
585605
describe("delete_resources_by_prefix", function () {
586606
callReusableTest("accepts next_cursor", cloudinary.v2.api.delete_resources_by_prefix, "prefix_foobar");
587607
return it("should allow deleting resources by prefix", function () {

0 commit comments

Comments
 (0)