Fixes of bugs caused by the public endpoint.
This commit is contained in:
parent
efbfa2b366
commit
213039c141
10 changed files with 79 additions and 52 deletions
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
function base(text, trustedBaseUrl, sandboxBaseUrl) {
|
||||
function _getBases(trustedBaseUrl, sandboxBaseUrl, publicBaseUrl) {
|
||||
if (trustedBaseUrl.endsWith('/')) {
|
||||
trustedBaseUrl = trustedBaseUrl.substring(0, trustedBaseUrl.length - 1);
|
||||
}
|
||||
|
@ -9,32 +9,54 @@ function base(text, trustedBaseUrl, sandboxBaseUrl) {
|
|||
sandboxBaseUrl = sandboxBaseUrl.substring(0, sandboxBaseUrl.length - 1);
|
||||
}
|
||||
|
||||
text = text.split('[URL_BASE]').join(trustedBaseUrl);
|
||||
text = text.split('[SANDBOX_URL_BASE]').join(sandboxBaseUrl);
|
||||
text = text.split('[ENCODED_URL_BASE]').join(encodeURIComponent(trustedBaseUrl));
|
||||
text = text.split('[ENCODED_SANDBOX_URL_BASE]').join(encodeURIComponent(sandboxBaseUrl));
|
||||
if (publicBaseUrl.endsWith('/')) {
|
||||
publicBaseUrl = publicBaseUrl.substring(0, publicBaseUrl.length - 1);
|
||||
}
|
||||
|
||||
return {trustedBaseUrl, sandboxBaseUrl, publicBaseUrl};
|
||||
}
|
||||
|
||||
function getMergeTagsForBases(trustedBaseUrl, sandboxBaseUrl, publicBaseUrl) {
|
||||
const bases = _getBases(trustedBaseUrl, sandboxBaseUrl, publicBaseUrl);
|
||||
|
||||
return {
|
||||
URL_BASE: bases.publicBaseUrl,
|
||||
TRUSTED_URL_BASE: bases.trustedBaseUrl,
|
||||
SANDBOX_URL_BASE: bases.sandboxBaseUrl,
|
||||
ENCODED_URL_BASE: encodeURIComponent(bases.publicBaseUrl),
|
||||
ENCODED_TRUSTED_URL_BASE: encodeURIComponent(bases.trustedBaseUrl),
|
||||
ENCODED_SANDBOX_URL_BASE: encodeURIComponent(bases.sandboxBaseUrl)
|
||||
};
|
||||
}
|
||||
|
||||
function base(text, trustedBaseUrl, sandboxBaseUrl, publicBaseUrl) {
|
||||
const bases = _getBases(trustedBaseUrl, sandboxBaseUrl, publicBaseUrl);
|
||||
|
||||
text = text.split('[URL_BASE]').join(bases.publicBaseUrl);
|
||||
text = text.split('[TRUSTED_URL_BASE]').join(bases.trustedBaseUrl);
|
||||
text = text.split('[SANDBOX_URL_BASE]').join(bases.sandboxBaseUrl);
|
||||
text = text.split('[ENCODED_URL_BASE]').join(encodeURIComponent(bases.publicBaseUrl));
|
||||
text = text.split('[ENCODED_TRUSTED_URL_BASE]').join(encodeURIComponent(bases.trustedBaseUrl));
|
||||
text = text.split('[ENCODED_SANDBOX_URL_BASE]').join(encodeURIComponent(bases.sandboxBaseUrl));
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
function unbase(text, trustedBaseUrl, sandboxBaseUrl, treatSandboxAsTrusted = false) {
|
||||
if (trustedBaseUrl.endsWith('/')) {
|
||||
trustedBaseUrl = trustedBaseUrl.substring(0, trustedBaseUrl.length - 1);
|
||||
}
|
||||
function unbase(text, trustedBaseUrl, sandboxBaseUrl, publicBaseUrl, treatAllAsPublic = false) {
|
||||
const bases = _getBases(trustedBaseUrl, sandboxBaseUrl, publicBaseUrl);
|
||||
|
||||
if (sandboxBaseUrl.endsWith('/')) {
|
||||
sandboxBaseUrl = sandboxBaseUrl.substring(0, sandboxBaseUrl.length - 1);
|
||||
}
|
||||
|
||||
text = text.split(trustedBaseUrl).join('[URL_BASE]');
|
||||
text = text.split(sandboxBaseUrl).join(treatSandboxAsTrusted ? '[URL_BASE]' : '[SANDBOX_URL_BASE]');
|
||||
text = text.split(encodeURIComponent(trustedBaseUrl)).join('[ENCODED_URL_BASE]');
|
||||
text = text.split(encodeURIComponent(sandboxBaseUrl)).join(treatSandboxAsTrusted ? '[ENCODED_URL_BASE]' : '[ENCODED_SANDBOX_URL_BASE]');
|
||||
text = text.split(bases.publicBaseUrl).join('[URL_BASE]');
|
||||
text = text.split(bases.trustedBaseUrl).join(treatAllAsPublic ? '[URL_BASE]' : '[TRUSTED_URL_BASE]');
|
||||
text = text.split(bases.sandboxBaseUrl).join(treatAllAsPublic ? '[URL_BASE]' : '[SANDBOX_URL_BASE]');
|
||||
text = text.split(encodeURIComponent(bases.publicBaseUrl)).join('[ENCODED_URL_BASE]');
|
||||
text = text.split(encodeURIComponent(bases.trustedBaseUrl)).join(treatAllAsPublic ? '[ENCODED_URL_BASE]' : '[ENCODED_TRUSTED_URL_BASE]');
|
||||
text = text.split(encodeURIComponent(bases.sandboxBaseUrl)).join(treatAllAsPublic ? '[ENCODED_URL_BASE]' : '[ENCODED_SANDBOX_URL_BASE]');
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
base,
|
||||
unbase
|
||||
unbase,
|
||||
getMergeTagsForBases
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue