X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/5f40f3d3559ba3705c3a788d84e33ff8221bd0bd..cd015a3c1aa2511da7c0063125a24065d37799bb:/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 261f5a87..9140e457 100644 --- a/src/views-components/context-menu/actions/helpers.ts +++ b/src/views-components/context-menu/actions/helpers.ts @@ -2,7 +2,8 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { extractUuidKind, ResourceKind } from "~/models/resource"; +import { REDIRECT_TO_DOWNLOAD_KEY, REDIRECT_TO_PREVIEW_KEY } from "common/redirect-to"; +import { extractUuidKind, ResourceKind } from "models/resource"; export const sanitizeToken = (href: string, tokenAsQueryParam = true): string => { const [prefix, suffix] = href.split('/t='); @@ -13,11 +14,15 @@ export const sanitizeToken = (href: string, tokenAsQueryParam = true): string => return `${[prefix, ...rest].join('/')}${tokenAsQueryParam ? `${sep}api_token=${token}` : ''}`; }; -export const getClipboardUrl = (href: string, shouldSanitizeToken = true): string => { +/** + * @returns A shareable token-free WB2 url that redirects to keep-web after login + */ +export const getCollectionItemClipboardUrl = (href: string, shouldSanitizeToken = true, inline = false): string => { const { origin } = window.location; const url = shouldSanitizeToken ? sanitizeToken(href, false) : href; + const redirectKey = inline ? REDIRECT_TO_PREVIEW_KEY : REDIRECT_TO_DOWNLOAD_KEY; - return shouldSanitizeToken ? `${origin}?redirectTo=${url}` : `${origin}${url}`; + return shouldSanitizeToken ? `${origin}?${redirectKey}=${url}` : `${origin}${url}`; }; export const getInlineFileUrl = (url: string, keepWebSvcUrl: string, keepWebInlineSvcUrl: string): string => { @@ -43,4 +48,11 @@ export const getInlineFileUrl = (url: string, keepWebSvcUrl: string, keepWebInli inlineUrl = inlineUrl.replace(`/c=${collMatch[1]}`, ''); } return inlineUrl; -}; \ No newline at end of file +}; + +export const isInlineFileUrlSafe = (url: string, keepWebSvcUrl: string, keepWebInlineSvcUrl: string): boolean => { + let inlineUrl = keepWebInlineSvcUrl !== "" + ? url.replace(keepWebSvcUrl, keepWebInlineSvcUrl) + : url; + return inlineUrl.indexOf('*.') > -1; +}