Skip to content

Commit e306a41

Browse files
feat: allow deleting resources by asset_ids (#701)
* feat: allow deleting resources by asset_ids * add URI array * add function to the list of v2 adapters * add the typescript functions * remove .only --------- Co-authored-by: Tia Esguerra <[email protected]>
1 parent 8d9b2a0 commit e306a41

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

lib/api.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ exports.delete_resources = function delete_resources(public_ids, callback, optio
171171
}), callback, options);
172172
};
173173

174+
exports.delete_resources_by_asset_ids = function delete_resources_by_asset_ids(asset_ids, callback, options = {}) {
175+
let uri = ["resources"]
176+
return call_api("delete", uri, deleteResourcesParams(options, {
177+
"asset_ids[]": asset_ids
178+
}), callback, options);
179+
};
180+
174181
exports.delete_resources_by_prefix = function delete_resources_by_prefix(prefix, callback, options = {}) {
175182
let resource_type, type, uri;
176183
resource_type = options.resource_type || "image";

lib/v2/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ v1_adapters(exports, api, {
1818
restore_by_asset_ids: 1,
1919
update: 1,
2020
delete_resources: 1,
21+
delete_resources_by_asset_ids: 1,
2122
delete_resources_by_prefix: 1,
2223
delete_resources_by_tag: 1,
2324
delete_all_resources: 0,

test/integration/api/admin/api_spec.js

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

types/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,10 @@ declare module 'cloudinary' {
10111011

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

1014+
function delete_resources_by_asset_ids(asset_ids: string[], callback?: ResponseCallback): Promise<ResourceApiResponse>;
1015+
1016+
function delete_resources_by_asset_ids(asset_ids: string[], options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<ResourceApiResponse>;
1017+
10141018
function delete_resources_by_prefix(prefix: string, options?: AdminAndResourceOptions, callback?: ResponseCallback): Promise<any>;
10151019

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

0 commit comments

Comments
 (0)