Skip to content

Commit 4947af7

Browse files
igystrausr
authored andcommitted
Add support for 'delete folder' API
1 parent d45437e commit 4947af7

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

lib-es5/api.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,14 @@ exports.sub_folders = function sub_folders(path, callback) {
458458
return call_api("get", uri, {}, callback, options);
459459
};
460460

461+
exports.delete_folder = function delete_folder(path, callback) {
462+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
463+
464+
var uri = void 0;
465+
uri = ["folders", path];
466+
return call_api("delete", uri, {}, callback, options);
467+
};
468+
461469
exports.upload_mappings = function upload_mappings(callback) {
462470
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
463471

lib-es5/v2/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ v1_adapters(exports, api, {
3333
create_upload_preset: 0,
3434
root_folders: 0,
3535
sub_folders: 1,
36+
delete_folder: 1,
3637
upload_mappings: 0,
3738
upload_mapping: 1,
3839
delete_upload_mapping: 1,

lib/api.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ exports.sub_folders = function sub_folders(path, callback, options = {}) {
366366
return call_api("get", uri, {}, callback, options);
367367
};
368368

369+
exports.delete_folder = function delete_folder(path, callback, options = {}) {
370+
let uri;
371+
uri = ["folders", path];
372+
return call_api("delete", uri, {}, callback, options);
373+
};
374+
369375
exports.upload_mappings = function upload_mappings(callback, options = {}) {
370376
let params;
371377
params = only(options, "next_cursor", "max_results");

lib/v2/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ v1_adapters(exports, api, {
3131
create_upload_preset: 0,
3232
root_folders: 0,
3333
sub_folders: 1,
34+
delete_folder: 1,
3435
upload_mappings: 0,
3536
upload_mapping: 1,
3637
delete_upload_mapping: 1,

test/api_spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,31 @@ describe("api", function () {
856856
expect().fail('error test_folder_not_exists should not pass to "then" handler but "catch"');
857857
}).catch(({ error }) => expect(error.message).to.eql('Can\'t find folder with path test_folder_not_exists'));
858858
});
859+
describe("delete folders", function() {
860+
this.timeout(helper.TIMEOUT_MEDIUM);
861+
const folderPath= "test_folder/delete_folder/"+TEST_TAG;
862+
before(function(){
863+
return cloudinary.v2.uploader.upload(IMAGE_FILE, {
864+
folder: folderPath,
865+
tags: UPLOAD_TAGS
866+
}).delay(2 * 1000).then(function() {
867+
return cloudinary.v2.api.delete_resources_by_prefix(folderPath)
868+
.then(() => cloudinary.v2.api.sub_folders(folderPath).then(folder => {
869+
expect(folder).not.to.be(null);
870+
expect(folder["total_count"]).to.eql(0);
871+
expect(folder["folders"]).to.be.empty;
872+
}));
873+
});
874+
});
875+
it('should delete an empty folder', function () {
876+
this.timeout(helper.TIMEOUT_MEDIUM);
877+
return cloudinary.v2.api.delete_folder(
878+
folderPath
879+
).delay(2 * 1000).then(() => cloudinary.v2.api.sub_folders(folderPath)
880+
).then(()=> expect().fail()
881+
).catch(({error}) => expect(error.message).to.contain("Can't find folder with path"));
882+
});
883+
});
859884
describe('.restore', function () {
860885
this.timeout(helper.TIMEOUT_MEDIUM);
861886

0 commit comments

Comments
 (0)