1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 export const sanitizeToken = (href: string, tokenAsQueryParam = true): string => {
6 const [prefix, suffix] = href.split('/t=');
7 const [token1, token2, token3, ...rest] = suffix.split('/');
8 const token = `${token1}/${token2}/${token3}`;
9 const sep = href.indexOf("?") > -1 ? "&" : "?";
11 return `${[prefix, ...rest].join('/')}${tokenAsQueryParam ? `${sep}api_token=${token}` : ''}`;
14 export const getClipboardUrl = (href: string, shouldSanitizeToken = true): string => {
15 const { origin } = window.location;
16 const url = shouldSanitizeToken ? sanitizeToken(href, false) : href;
18 return shouldSanitizeToken ? `${origin}?redirectTo=${url}` : `${origin}${url}`;
21 export const getInlineFileUrl = (url: string, keepWebSvcUrl: string, keepWebInlineSvcUrl: string): string => {
22 const collUuidMatch = url.match(/\/c=([a-z0-9-]+)\//);
23 if (collUuidMatch === null) { return ''; }
24 const collUuid = collUuidMatch[1];
25 let inlineUrl = keepWebInlineSvcUrl !== ""
26 ? url.replace(keepWebSvcUrl, keepWebInlineSvcUrl)
28 let uuidOnHostname = false;
29 // Inline URLs as 'https://*.collections.example.com' or
30 // 'https://*--collections.example.com' should get the uuid on their hostnames
31 // See: https://doc.arvados.org/v2.1/api/keep-web-urls.html
32 if (inlineUrl.indexOf('*.') > -1) {
33 inlineUrl = inlineUrl.replace('*.', `${collUuid}.`);
34 uuidOnHostname = true;
35 } else if (inlineUrl.indexOf('*--') > -1) {
36 inlineUrl = inlineUrl.replace('*--', `${collUuid}--`);
37 uuidOnHostname = true;
40 inlineUrl = inlineUrl.replace(`/c=${collUuid}`, '');