Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow deleting resources by asset_ids #701

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

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

why asset_ids[]? http client should encode this parameter

}), 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";
Expand Down
20 changes: 20 additions & 0 deletions test/integration/api/admin/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down