2019-03-27 08:49:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-08-11 19:50:06 +00:00
|
|
|
const {renderTag} = require('../../shared/templates');
|
|
|
|
|
2019-08-07 12:29:58 +00:00
|
|
|
function convertFileURLs(sourceCustom, fromEntityType, fromEntityId, toEntityType, toEntityId) {
|
2019-03-27 08:49:29 +00:00
|
|
|
|
2019-08-11 19:50:06 +00:00
|
|
|
const tagLanguage = sourceCustom.tag_language;
|
|
|
|
|
2019-03-27 08:49:29 +00:00
|
|
|
function convertText(text) {
|
|
|
|
if (text) {
|
|
|
|
const fromUrl = `/files/${fromEntityType}/file/${fromEntityId}`;
|
|
|
|
const toUrl = `/files/${toEntityType}/file/${toEntityId}`;
|
|
|
|
|
|
|
|
const encodedFromUrl = encodeURIComponent(fromUrl);
|
|
|
|
const encodedToUrl = encodeURIComponent(toUrl);
|
|
|
|
|
2019-08-11 19:50:06 +00:00
|
|
|
text = text.split(renderTag(tagLanguage, 'URL_BASE') + fromUrl).join(renderTag(tagLanguage, 'URL_BASE') + toUrl);
|
|
|
|
text = text.split(renderTag(tagLanguage,'SANDBOX_URL_BASE') + fromUrl).join(renderTag(tagLanguage, 'SANDBOX_URL_BASE') + toUrl);
|
|
|
|
text = text.split(renderTag(tagLanguage, 'ENCODED_URL_BASE') + encodedFromUrl).join(renderTag(tagLanguage, 'ENCODED_URL_BASE') + encodedToUrl);
|
|
|
|
text = text.split(renderTag(tagLanguage, 'ENCODED_SANDBOX_URL_BASE') + encodedFromUrl).join(renderTag(tagLanguage, 'ENCODED_SANDBOX_URL_BASE') + encodedToUrl);
|
2019-03-27 08:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceCustom.html = convertText(sourceCustom.html);
|
|
|
|
sourceCustom.text = convertText(sourceCustom.text);
|
|
|
|
|
2019-08-07 12:29:58 +00:00
|
|
|
if (sourceCustom.type === 'mosaico' || sourceCustom.type === 'mosaicoWithFsTemplate') {
|
2019-03-27 08:49:29 +00:00
|
|
|
sourceCustom.data.model = convertText(sourceCustom.data.model);
|
|
|
|
sourceCustom.data.model = convertText(sourceCustom.data.model);
|
|
|
|
sourceCustom.data.metadata = convertText(sourceCustom.data.metadata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 20:36:44 +00:00
|
|
|
module.exports.convertFileURLs = convertFileURLs;
|