UNPKG

@darwino/darwino

Version:

A set of Javascript classes and utilities

81 lines (67 loc) 2.47 kB
/*#!COPYRIGHT HEADER! - CONFIDENTIAL * * Darwino Inc Confidential. * * (c) Copyright Darwino Inc. 2014-2016. * * Notice: The information contained in the source code for these files is the property * of Darwino Inc. which, with its licensors, if any, owns all the intellectual property * rights, including all copyright rights thereto. Such information may only be used * for debugging, troubleshooting and informational purposes. All other uses of this information, * including any production or commercial uses, are prohibited. */ import queryString from 'query-string'; import DEV_OPTIONS from './dev'; /* * Rich text utilities */ function richTextToDisplayFormat(_ref, html) { var { databaseId, storeId, instanceId, unid } = _ref; if (html) { var INLINE_IMAGE_STORAGE_PATTERN = /src="\$document-attachment\/([^"]+(\||%7C){2}[^"]+)"/g; return html.replace(INLINE_IMAGE_STORAGE_PATTERN, 'src="' + DEV_OPTIONS.serverPrefix + '$darwino-jstore' + '/databases/' + encodeURIComponent(databaseId) + '/stores/' + encodeURIComponent(storeId) + '/documents/' + encodeURIComponent(unid) + '/attachments/$1' + (instanceId ? '?instance=' + encodeURIComponent(instanceId) : '') + '"'); } return html; } function richTextToStorageFormat(_ref2, html) { var { databaseId, storeId, instanceId, unid } = _ref2; if (html) { var INLINE_IMAGE_DISPLAY_PATTERN = /src="[^\"]*\$darwino-jstore\/databases\/([^\/]+)\/stores\/([^\/]+)\/documents\/([^\/]+)\/attachments\/([^\?]+)(\?instance=([^"]+))?"/g; return html.replace(INLINE_IMAGE_DISPLAY_PATTERN, 'src="$document-attachment/$4"'); } return html; } function renderAttachmentUrl(databaseId, storeId, unid, name) { return DEV_OPTIONS.serverPrefix + "$darwino-jstore/databases/".concat(encodeURIComponent(databaseId)) + "/stores/".concat(encodeURIComponent(storeId), "/") + "documents/".concat(encodeURIComponent(unid), "/") + "attachments/".concat(encodeURIComponent(name)); } function cleanAttachmentName(name) { if (!name) { return ""; } var inlineIndex = name.indexOf("||"); if (inlineIndex > -1) { return name.substring(inlineIndex + 2); } var attIndex = name.indexOf("^^"); if (attIndex > -1) { return name.substring(attIndex + 2); } return name; } export default { richTextToDisplayFormat, richTextToStorageFormat, renderAttachmentUrl, cleanAttachmentName }; //# sourceMappingURL=Richtext.js.map