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
4 changes: 1 addition & 3 deletions lib-es5/api_client/call_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ var ensurePresenceOf = utils.ensurePresenceOf;

function call_api(method, uri, params, callback, options) {
ensurePresenceOf({ method, uri });
var cloudinary = ensureOption(options, "upload_prefix", "https://api.cloudinary.com");
var cloud_name = ensureOption(options, "cloud_name");
var api_url = [cloudinary, "v1_1", cloud_name].concat(uri).join("/");
var api_url = utils.base_api_url(uri, options);
var auth = {
key: ensureOption(options, "api_key"),
secret: ensureOption(options, "api_secret")
Expand Down
8 changes: 6 additions & 2 deletions lib-es5/utils/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ var PREDEFINED_VARS = {
"width": "w"
};

var TRANSFORMATION_PARAMS = ['angle', 'aspect_ratio', 'audio_codec', 'audio_frequency', 'background', 'bit_rate', 'border', 'color', 'color_space', 'crop', 'default_image', 'delay', 'density', 'dpr', 'duration', 'effect', 'end_offset', 'fetch_format', 'flags', 'fps', 'gravity', 'height', 'if', 'keyframe_interval', 'offset', 'opacity', 'overlay', 'page', 'prefix', 'quality', 'radius', 'raw_transformation', 'responsive_width', 'size', 'start_offset', 'streaming_profile', 'transformation', 'underlay', 'variables', 'video_codec', 'video_sampling', 'width', 'x', 'y', 'zoom'];
var TRANSFORMATION_PARAMS = ['angle', 'aspect_ratio', 'audio_codec', 'audio_frequency', 'background', 'bit_rate', 'border', 'color', 'color_space', 'crop', 'default_image', 'delay', 'density', 'dpr', 'duration', 'effect', 'end_offset', 'fetch_format', 'flags', 'fps', 'gravity', 'height', 'if', 'keyframe_interval', 'offset', 'opacity', 'overlay', 'page', 'prefix', 'quality', 'radius', 'raw_transformation', 'responsive_width', 'size', 'start_offset', 'streaming_profile', 'transformation', 'underlay', 'variables', 'video_codec', 'video_sampling', 'width', 'x', 'y', 'zoom' // + any key that starts with '$'
];

var LAYER_KEYWORD_PARAMS = {
font_weight: "normal",
Expand All @@ -67,6 +68,8 @@ var LAYER_KEYWORD_PARAMS = {
stroke: "none"
};

var UPLOAD_PREFIX = "https://api.cloudinary.com";

module.exports = {
DEFAULT_RESPONSIVE_WIDTH_TRANSFORMATION,
DEFAULT_POSTER_OPTIONS,
Expand All @@ -75,5 +78,6 @@ module.exports = {
PREDEFINED_VARS,
LAYER_KEYWORD_PARAMS,
TRANSFORMATION_PARAMS,
SIMPLE_PARAMS
SIMPLE_PARAMS,
UPLOAD_PREFIX
};
39 changes: 35 additions & 4 deletions lib-es5/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ var _require2 = require('./consts'),
PREDEFINED_VARS = _require2.PREDEFINED_VARS,
LAYER_KEYWORD_PARAMS = _require2.LAYER_KEYWORD_PARAMS,
TRANSFORMATION_PARAMS = _require2.TRANSFORMATION_PARAMS,
SIMPLE_PARAMS = _require2.SIMPLE_PARAMS;
SIMPLE_PARAMS = _require2.SIMPLE_PARAMS,
UPLOAD_PREFIX = _require2.UPLOAD_PREFIX;

function textStyle(layer) {
var keywords = [];
Expand Down Expand Up @@ -916,14 +917,21 @@ function unsigned_url_prefix(source, cloud_name, private_cdn, cdn_subdomain, sec
return prefix;
}

function base_api_url() {
var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

var cloudinary = ensureOption(options, "upload_prefix", UPLOAD_PREFIX);
var cloud_name = ensureOption(options, "cloud_name");
return [cloudinary, "v1_1", cloud_name].concat(path).join("/");
}

function api_url() {
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'upload';
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

var cloudinary = ensureOption(options, "upload_prefix", "https://api.cloudinary.com");
var cloud_name = ensureOption(options, "cloud_name");
var resource_type = options.resource_type || "image";
return [cloudinary, "v1_1", cloud_name, resource_type, action].join("/");
return base_api_url([resource_type, action], options);
}

function random_public_id() {
Expand Down Expand Up @@ -1060,6 +1068,26 @@ function zip_download_url(tag) {
return exports.api_url("download_tag.zip", options) + "?" + hashToQuery(params);
}

/**
* The returned url should allow downloading the backedup asset based on the
* version and asset id
* asset and version id are returned with resource(<PUBLIC_ID1>, { versions: true })
* @param asset_id
* @param version_id
* @param options
* @returns {string }
*/
function download_backedup_asset(asset_id, version_id) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

var params = exports.sign_request({
timestamp: options.timestamp || exports.timestamp(),
asset_id: asset_id,
version_id: version_id
}, options);
return exports.base_api_url(['download_backup'], options) + "?" + hashToQuery(params);
}

/**
* Returns a URL that when invokes creates an archive and returns it.
* @param {object} options
Expand Down Expand Up @@ -1523,6 +1551,9 @@ exports.only = pickOnlyExistingValues; // for backwards compatibility
exports.pickOnlyExistingValues = pickOnlyExistingValues;
exports.jsonArrayParam = jsonArrayParam;
exports.download_folder = download_folder;
exports.base_api_url = base_api_url;
exports.download_backedup_asset = download_backedup_asset;

// was exported before, so kept for backwards compatibility
exports.DEFAULT_POSTER_OPTIONS = DEFAULT_POSTER_OPTIONS;
exports.DEFAULT_VIDEO_SOURCE_TYPES = DEFAULT_VIDEO_SOURCE_TYPES;
Expand Down
4 changes: 1 addition & 3 deletions lib/api_client/call_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const { ensurePresenceOf } = utils;

function call_api(method, uri, params, callback, options) {
ensurePresenceOf({ method, uri });
const cloudinary = ensureOption(options, "upload_prefix", "https://api.cloudinary.com");
const cloud_name = ensureOption(options, "cloud_name");
const api_url = [cloudinary, "v1_1", cloud_name].concat(uri).join("/");
const api_url = utils.base_api_url(uri, options);
const auth = {
key: ensureOption(options, "api_key"),
secret: ensureOption(options, "api_secret")
Expand Down
5 changes: 4 additions & 1 deletion lib/utils/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ const LAYER_KEYWORD_PARAMS = {
stroke: "none"
};

const UPLOAD_PREFIX = "https://api.cloudinary.com";

module.exports = {
DEFAULT_RESPONSIVE_WIDTH_TRANSFORMATION,
DEFAULT_POSTER_OPTIONS,
Expand All @@ -137,5 +139,6 @@ module.exports = {
PREDEFINED_VARS,
LAYER_KEYWORD_PARAMS,
TRANSFORMATION_PARAMS,
SIMPLE_PARAMS
SIMPLE_PARAMS,
UPLOAD_PREFIX
};
34 changes: 30 additions & 4 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ const {
PREDEFINED_VARS,
LAYER_KEYWORD_PARAMS,
TRANSFORMATION_PARAMS,
SIMPLE_PARAMS
SIMPLE_PARAMS,
UPLOAD_PREFIX
} = require('./consts');

function textStyle(layer) {
Expand Down Expand Up @@ -857,11 +858,15 @@ function unsigned_url_prefix(
return prefix;
}

function api_url(action = 'upload', options = {}) {
let cloudinary = ensureOption(options, "upload_prefix", "https://api.cloudinary.com");
function base_api_url(path= [], options = {}) {
let cloudinary = ensureOption(options, "upload_prefix", UPLOAD_PREFIX);
let cloud_name = ensureOption(options, "cloud_name");
return [cloudinary, "v1_1", cloud_name].concat(path).join("/");
}

function api_url(action = 'upload', options = {}) {
let resource_type = options.resource_type || "image";
return [cloudinary, "v1_1", cloud_name, resource_type, action].join("/");
return base_api_url([resource_type, action], options);
}

function random_public_id() {
Expand Down Expand Up @@ -972,6 +977,24 @@ function zip_download_url(tag, options = {}) {
return exports.api_url("download_tag.zip", options) + "?" + hashToQuery(params);
}

/**
* The returned url should allow downloading the backedup asset based on the
* version and asset id
* asset and version id are returned with resource(<PUBLIC_ID1>, { versions: true })
* @param asset_id
* @param version_id
* @param options
* @returns {string }
*/
function download_backedup_asset(asset_id, version_id, options = {}) {
let params = exports.sign_request({
timestamp: options.timestamp || exports.timestamp(),
asset_id: asset_id,
version_id: version_id
}, options);
return exports.base_api_url(['download_backup'], options) + "?" + hashToQuery(params);
}

/**
* Returns a URL that when invokes creates an archive and returns it.
* @param {object} options
Expand Down Expand Up @@ -1396,6 +1419,9 @@ exports.only = pickOnlyExistingValues; // for backwards compatibility
exports.pickOnlyExistingValues = pickOnlyExistingValues;
exports.jsonArrayParam = jsonArrayParam;
exports.download_folder = download_folder;
exports.base_api_url = base_api_url;
exports.download_backedup_asset = download_backedup_asset;

// was exported before, so kept for backwards compatibility
exports.DEFAULT_POSTER_OPTIONS = DEFAULT_POSTER_OPTIONS;
exports.DEFAULT_VIDEO_SOURCE_TYPES = DEFAULT_VIDEO_SOURCE_TYPES;
Expand Down
8 changes: 8 additions & 0 deletions test/archivespec.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,12 @@ describe("archive", function () {
expect(download_folder_url).to.contain('use_original_filename');
});
});

describe('download_backedup_asset', function(){
it('should return url with asset and version id', function(){
let download_backedup_asset_url = utils.download_backedup_asset('b71b23d9c89a81a254b88a91a9dad8cd', '0e493356d8a40b856c4863c026891a4e');
expect(download_backedup_asset_url).to.contain('asset_id');
expect(download_backedup_asset_url).to.contain('version_id');
});
});
});