Merge branch '17256-file-selection-dialog-issue'
[arvados.git] / src / views-components / context-menu / actions / helpers.ts
index 578af2053f74d543cf8d00fec26b87d1e4c8c8c6..ce5dd8b1b2030f1e706f609ef381960760e184cf 100644 (file)
@@ -2,8 +2,6 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { REDIRECT_TO_APPLY_TO_PATH } from "~/common/redirect-to";
-
 export const sanitizeToken = (href: string, tokenAsQueryParam = true): string => {
     const [prefix, suffix] = href.split('/t=');
     const [token1, token2, token3, ...rest] = suffix.split('/');
@@ -17,5 +15,29 @@ export const getClipboardUrl = (href: string, shouldSanitizeToken = true): strin
     const { origin } = window.location;
     const url = shouldSanitizeToken ? sanitizeToken(href, false) : href;
 
-    return `${origin}${!shouldSanitizeToken ? `?${REDIRECT_TO_APPLY_TO_PATH}=true&` : `?`}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