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

Support multiple resource_types in ZIP generation #348

Merged
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
4 changes: 3 additions & 1 deletion lib-es5/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@ function patchFetchFormat() {
function url(public_id) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};


var signature = void 0,
source_to_sign = void 0;
utils.patchFetchFormat(options);
Expand Down Expand Up @@ -1039,6 +1038,8 @@ function zip_download_url(tag) {
* @param {string|Array} [options.tags] list of tags to include in the archive
* @param {string|Array<string>} [options.public_ids] list of public_ids to include in the archive
* @param {string|Array<string>} [options.prefixes] list of prefixes of public IDs (e.g., folders).
* @param {string|Array<string>} [options.fully_qualified_public_ids] list of fully qualified public_ids to include
* in the archive.
* @param {string|Array<string>} [options.transformations] list of transformations.
* The derived images of the given transformations are included in the archive. Using the string representation of
* multiple chained transformations as we use for the 'eager' upload parameter.
Expand Down Expand Up @@ -1260,6 +1261,7 @@ function archive_params() {
mode: options.mode,
notification_url: options.notification_url,
prefixes: options.prefixes && toArray(options.prefixes),
fully_qualified_public_ids: options.fully_qualified_public_ids && toArray(options.fully_qualified_public_ids),
public_ids: options.public_ids && toArray(options.public_ids),
skip_transformation_name: exports.as_safe_bool(options.skip_transformation_name),
tags: options.tags && toArray(options.tags),
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,6 @@ function patchFetchFormat(options = {}) {
}

function url(public_id, options = {}) {

let signature, source_to_sign;
utils.patchFetchFormat(options);
let type = consumeOption(options, "type", null);
Expand Down Expand Up @@ -953,6 +952,8 @@ function zip_download_url(tag, options = {}) {
* @param {string|Array} [options.tags] list of tags to include in the archive
* @param {string|Array<string>} [options.public_ids] list of public_ids to include in the archive
* @param {string|Array<string>} [options.prefixes] list of prefixes of public IDs (e.g., folders).
* @param {string|Array<string>} [options.fully_qualified_public_ids] list of fully qualified public_ids to include
* in the archive.
* @param {string|Array<string>} [options.transformations] list of transformations.
* The derived images of the given transformations are included in the archive. Using the string representation of
* multiple chained transformations as we use for the 'eager' upload parameter.
Expand Down Expand Up @@ -1157,6 +1158,7 @@ function archive_params(options = {}) {
mode: options.mode,
notification_url: options.notification_url,
prefixes: options.prefixes && toArray(options.prefixes),
fully_qualified_public_ids: options.fully_qualified_public_ids && toArray(options.fully_qualified_public_ids),
public_ids: options.public_ids && toArray(options.public_ids),
skip_transformation_name: exports.as_safe_bool(options.skip_transformation_name),
tags: options.tags && toArray(options.tags),
Expand Down
17 changes: 17 additions & 0 deletions test/archivespec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ const helper = require("./spechelper");
const { utils, api, uploader } = cloudinary.v2;
const TEST_TAG = helper.TEST_TAG;
const IMAGE_URL = helper.IMAGE_URL;
const VIDEO_URL = helper.VIDEO_URL;
const sharedExamples = helper.sharedExamples;
const includeContext = helper.includeContext;
const ARCHIVE_TAG = TEST_TAG + "_archive";
const PUBLIC_ID1 = ARCHIVE_TAG + "_1";
const PUBLIC_ID2 = ARCHIVE_TAG + "_2";
const PUBLIC_ID_RAW = ARCHIVE_TAG + "_3";
const FULLY_QUALIFIED_IMAGE = "image/upload/sample";
const FULLY_QUALIFIED_VIDEO = "video/upload/dog";

sharedExamples('archive', function () {
before("Verify Configuration", function () {
Expand Down Expand Up @@ -56,6 +59,12 @@ sharedExamples('archive', function () {
resource_type: "raw",
tags: helper.UPLOAD_TAGS.concat([ARCHIVE_TAG]),
}),
uploader.upload(VIDEO_URL,
{
public_id: "dog",
resource_type: "video",
tags: helper.UPLOAD_TAGS.concat([ARCHIVE_TAG]),
}),
]);
});
after(function () {
Expand Down Expand Up @@ -152,6 +161,14 @@ describe("archive", function () {
sinon.assert.calledWith(write, sinon.match(helper.uploadParamMatcher("target_format", "zip")));
});
});
it('should create archive with "zip" format and include multiple resource types', function () {
return uploader.create_zip({
fully_qualified_public_ids: [FULLY_QUALIFIED_IMAGE, FULLY_QUALIFIED_VIDEO],
resource_type: "auto",
}).then((result) => {
expect(result.file_count).to.eql(2);
});
});
});
});
});
1 change: 1 addition & 0 deletions test/spechelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ exports.LARGE_VIDEO = "test/resources/CloudBookStudy-HD.mp4";
exports.EMPTY_IMAGE = "test/resources/empty.gif";
exports.RAW_FILE = "test/resources/docx.docx";
exports.ICON_FILE = "test/resources/favicon.ico";
exports.VIDEO_URL = "http://res.cloudinary.com/demo/video/upload/dog.mp4";
exports.IMAGE_URL = "http://res.cloudinary.com/demo/image/upload/sample";

exports.test_cloudinary_url = function (public_id, options, expected_url, expected_options) {
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ declare module 'cloudinary' {
notification_url?: string;
prefixes?: string;
public_ids?: string[] | string;
fully_qualified_public_ids?: string[] | string;
skip_transformation_name?: boolean;
tags?: string | string[];
target_format?: TargetArchiveFormat;
Expand Down