X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/35ce0164f3863e7117fade1319ed3c2789bc216a..353db93c2540a989d3bdd3f695ee07e707bdaf7a:/src/views-components/context-menu/actions/helpers.ts diff --git a/src/views-components/context-menu/actions/helpers.ts b/src/views-components/context-menu/actions/helpers.ts index 8dfcaca0e3..ce5dd8b1b2 100644 --- a/src/views-components/context-menu/actions/helpers.ts +++ b/src/views-components/context-menu/actions/helpers.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: AGPL-3.0 -export const sanitizeToken = (href: string, tokenAsQueryParam: boolean = true): string => { +export const sanitizeToken = (href: string, tokenAsQueryParam = true): string => { const [prefix, suffix] = href.split('/t='); const [token1, token2, token3, ...rest] = suffix.split('/'); const token = `${token1}/${token2}/${token3}`; @@ -11,9 +11,33 @@ export const sanitizeToken = (href: string, tokenAsQueryParam: boolean = true): return `${[prefix, ...rest].join('/')}${tokenAsQueryParam ? `${sep}api_token=${token}` : ''}`; }; -export const getClipboardUrl = (href: string): string => { +export const getClipboardUrl = (href: string, shouldSanitizeToken = true): string => { const { origin } = window.location; - const url = sanitizeToken(href, false); + const url = shouldSanitizeToken ? sanitizeToken(href, false) : href; - return `${origin}?redirectTo=${url}`; + return shouldSanitizeToken ? `${origin}?redirectTo=${url}` : `${origin}${url}`; }; + +export const getInlineFileUrl = (url: string, keepWebSvcUrl: string, keepWebInlineSvcUrl: string): string => { + const collUuidMatch = url.match(/\/c=([a-z0-9-]+)\//); + if (collUuidMatch === null) { return ''; } + const collUuid = collUuidMatch[1]; + let inlineUrl = keepWebInlineSvcUrl !== "" + ? url.replace(keepWebSvcUrl, keepWebInlineSvcUrl) + : url; + let uuidOnHostname = false; + // Inline URLs as 'https://*.collections.example.com' or + // 'https://*--collections.example.com' should get the uuid on their hostnames + // See: https://doc.arvados.org/v2.1/api/keep-web-urls.html + if (inlineUrl.indexOf('*.') > -1) { + inlineUrl = inlineUrl.replace('*.', `${collUuid}.`); + uuidOnHostname = true; + } else if (inlineUrl.indexOf('*--') > -1) { + inlineUrl = inlineUrl.replace('*--', `${collUuid}--`); + uuidOnHostname = true; + } + if (uuidOnHostname) { + inlineUrl = inlineUrl.replace(`/c=${collUuid}`, ''); + } + return inlineUrl; +}; \ No newline at end of file