MCPcopy Create free account
hub / github.com/cloudinary/cloudinary_npm / url

Function url

lib/utils/index.js:799–922  ·  view source on GitHub ↗
(public_id, options = {})

Source from the content-addressed store, hash-verified

797}
798
799function url(public_id, options = {}) {
800 let signature, source_to_sign;
801 utils.patchFetchFormat(options);
802 let type = consumeOption(options, "type", null);
803 let transformation = utils.generate_transformation_string(options);
804
805 let resource_type = consumeOption(options, "resource_type", "image");
806 let version = consumeOption(options, "version");
807 let force_version = consumeOption(options, "force_version", config().force_version);
808 if (force_version == null) {
809 force_version = true;
810 }
811 let long_url_signature = !!consumeOption(options, "long_url_signature", config().long_url_signature);
812 let format = consumeOption(options, "format");
813 let shorten = consumeOption(options, "shorten", config().shorten);
814 let sign_url = consumeOption(options, "sign_url", config().sign_url);
815 let api_secret = consumeOption(options, "api_secret", config().api_secret);
816 let url_suffix = consumeOption(options, "url_suffix");
817 let use_root_path = consumeOption(options, "use_root_path", config().use_root_path);
818 let signature_algorithm = consumeOption(options, "signature_algorithm", config().signature_algorithm || DEFAULT_SIGNATURE_ALGORITHM);
819 if (long_url_signature) {
820 signature_algorithm = 'sha256';
821 }
822 let auth_token = consumeOption(options, "auth_token");
823 if (auth_token !== false) {
824 auth_token = exports.merge(config().auth_token, auth_token);
825 }
826 let preloaded = /^(image|raw)\/([a-z0-9_]+)\/v(\d+)\/([^#]+)$/.exec(public_id);
827 if (preloaded) {
828 resource_type = preloaded[1];
829 type = preloaded[2];
830 version = preloaded[3];
831 public_id = preloaded[4];
832 }
833 let original_source = public_id;
834 if (public_id == null) {
835 return original_source;
836 }
837 public_id = public_id.toString();
838 if (type === null && public_id.match(/^https?:\//i)) {
839 return original_source;
840 }
841 [resource_type, type] = finalize_resource_type(resource_type, type, url_suffix, use_root_path, shorten);
842 [public_id, source_to_sign] = finalize_source(public_id, format, url_suffix);
843
844 if (version == null && force_version && source_to_sign.indexOf("/") >= 0 && !source_to_sign.match(/^v[0-9]+/) && !source_to_sign.match(/^https?:\//)) {
845 version = 1;
846 }
847 if (version != null) {
848 version = `v${version}`;
849 } else {
850 version = null;
851 }
852
853 transformation = transformation.replace(/([^:])\/\//g, '$1/');
854 if (sign_url && isEmpty(auth_token)) {
855 let to_sign = [transformation, source_to_sign].filter(function (part) {
856 return (part != null) && part !== '';

Callers

nothing calls this directly

Calls 9

consumeOptionFunction · 0.85
finalize_resource_typeFunction · 0.85
finalize_sourceFunction · 0.85
compute_hashFunction · 0.85
getSDKVersionsFunction · 0.85
getAnalyticsOptionsFunction · 0.85
getSDKAnalyticsSignatureFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected