Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
publicUrlTransformed({ _meta } = {}, options = {}) {
if (!_meta) {
return null;
}
const { prettyName, ...transformation } = options;
// No formatting options provided, return the publicUrl field
if (!Object.keys(transformation).length) {
return this.publicUrl({ _meta });
}
const { public_id, format } = _meta;
// Docs: https://github.com/cloudinary/cloudinary_npm/blob/439586eac73cee7f2803cf19f885e98f237183b3/src/utils.coffee#L472 (LOL)
return cloudinary.url(public_id, {
type: 'upload',
format,
secure: true,
url_suffix: prettyName,
transformation,
cloud_name: this.cloudName,
});
}
};
// then `this` refers to our default scope block and kwargs
// are stored in context.hash
if (!options && context.hasOwnProperty('hash')) {
// strategy is to place context kwargs into options
options = context;
// bind our default inherited scope into context
context = this;
}
// safe guard to ensure context is never null
context = context === null ? undefined : context;
if ((context) && (context.public_id)) {
options.hash.secure = keystone.get('cloudinary secure') || false;
var imageName = context.public_id.concat('.', context.format);
return cloudinary.url(imageName, options.hash);
}
else {
return null;
}
};
var src = function (img, options) {
if (keystone.get('cloudinary secure')) {
options = options || {};
options.secure = true;
}
options.format = options.format || img.format;
return img.public_id ? cloudinary.url(img.public_id, options) : '';
};
responsiveImg: function (img, isBig) {
var baseSize = 300;
if (isBig) {
baseSize *= 2;
}
var out = {
_id: img._id,
src: {
mini: cloudinary.url(img.src, { format: "jpg", width: baseSize * 2/3, height: baseSize * 2/3, crop: "fill" }),
main: cloudinary.url(img.src, { format: "jpg", width: baseSize, height: baseSize, crop: "fill" }),
retina: cloudinary.url(img.src, { format: "jpg", width: baseSize * 2, height: baseSize * 2, crop: "fill" })
}
};
return out;
}
};
return '';
}
options = (typeof options === 'object') ? options : {};
if (!('fetch_format' in options) && keystone.get('cloudinary webp') !== false) {
options.fetch_format = 'auto';
}
if (!('progressive' in options) && keystone.get('cloudinary progressive') !== false) {
options.progressive = true;
}
if (!('secure' in options) && keystone.get('cloudinary secure')) {
options.secure = true;
}
options.version = item.get(paths.version);
options.format = options.format || item.get(paths.format);
return cloudinary.url(item.get(paths.public_id), options);
};
cloudinary.uploader.upload(image.path, function(result) {
resolve(cloudinary.url(result.public_id.concat(".", result.format), cloudinaryImageSetting ).replace('http://', 'https://'));
});
});
responsiveImg: function (img, isBig) {
var baseSize = 300;
if (isBig) {
baseSize *= 2;
}
var out = {
_id: img._id,
src: {
mini: cloudinary.url(img.src, { format: "jpg", width: baseSize * 2/3, height: baseSize * 2/3, crop: "fill" }),
main: cloudinary.url(img.src, { format: "jpg", width: baseSize, height: baseSize, crop: "fill" }),
retina: cloudinary.url(img.src, { format: "jpg", width: baseSize * 2, height: baseSize * 2, crop: "fill" })
}
};
return out;
}
};