Skip to content

Commit

Permalink
chore: reusing existing function
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudinary-pkoniu committed Jul 20, 2023
1 parent 7d2b883 commit 3b00b29
Showing 1 changed file with 8 additions and 28 deletions.
36 changes: 8 additions & 28 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,15 +735,18 @@ function patchFetchFormat(options = {}) {
}
}

function build_distribution_domain(options) {
const source = consumeOption(options, 'source', '');
function build_distribution_domain(source, options) {
const cloud_name = consumeOption(options, 'cloud_name', config().cloud_name);

if (!cloud_name) {
throw new Error('Must supply cloud_name in tag or in configuration');
}

const secure = consumeOption(options, 'secure', config().secure);
const ssl_detected = consumeOption(options, "ssl_detected", config().ssl_detected);
let secure = consumeOption(options, 'secure', config().secure);
if (secure === null) {
secure = ssl_detected || config().secure;
}

const private_cdn = consumeOption(options, 'private_cdn', config().private_cdn);
const cname = consumeOption(options, 'cname', config().cname);
const secure_distribution = consumeOption(options, 'secure_distribution', config().secure_distribution);
Expand All @@ -767,20 +770,6 @@ function url(public_id, options = {}) {
}
let long_url_signature = !!consumeOption(options, "long_url_signature", config().long_url_signature);
let format = consumeOption(options, "format");
let cloud_name = consumeOption(options, "cloud_name", config().cloud_name);
if (!cloud_name) {
throw "Unknown cloud_name";
}
let private_cdn = consumeOption(options, "private_cdn", config().private_cdn);
let secure_distribution = consumeOption(options, "secure_distribution", config().secure_distribution);
let secure = consumeOption(options, "secure", null);
let ssl_detected = consumeOption(options, "ssl_detected", config().ssl_detected);
if (secure === null) {
secure = ssl_detected || config().secure;
}
let cdn_subdomain = consumeOption(options, "cdn_subdomain", config().cdn_subdomain);
let secure_cdn_subdomain = consumeOption(options, "secure_cdn_subdomain", config().secure_cdn_subdomain);
let cname = consumeOption(options, "cname", config().cname);
let shorten = consumeOption(options, "shorten", config().shorten);
let sign_url = consumeOption(options, "sign_url", config().sign_url);
let api_secret = consumeOption(options, "api_secret", config().api_secret);
Expand Down Expand Up @@ -837,16 +826,7 @@ function url(public_id, options = {}) {
signature = hash.replace(/\//g, '_').replace(/\+/g, '-').substring(0, long_url_signature ? 32 : 8);
signature = `s--${signature}--`;
}
let prefix = unsigned_url_prefix(
public_id,
cloud_name,
private_cdn,
cdn_subdomain,
secure_cdn_subdomain,
cname,
secure,
secure_distribution
);
let prefix = build_distribution_domain(public_id, options);
let resultUrl = [prefix, resource_type, type, signature, transformation, version, public_id].filter(function (part) {
return (part != null) && part !== '';
}).join('/').replace(/ /g, '%20');
Expand Down

0 comments on commit 3b00b29

Please sign in to comment.