Skip to content
Merged
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
7 changes: 7 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

The brackets are intentional. They match the pattern in delete_resources()

}), 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
1 change: 1 addition & 0 deletions lib/v2/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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("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
4 changes: 4 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,10 @@ declare module 'cloudinary' {

function delete_resources(value: string[], options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<any>;

function delete_resources_by_asset_ids(asset_ids: string[], callback?: ResponseCallback): Promise<ResourceApiResponse>;

function delete_resources_by_asset_ids(asset_ids: string[], options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<ResourceApiResponse>;

function delete_resources_by_prefix(prefix: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<any>;

function delete_resources_by_prefix(prefix: string, callback?: ResponseCallback): Promise<any>;
Expand Down