[ARVADOS-WORKBENCH2] created: 2.1.0-166-g5f40f3d3

Git user git at public.arvados.org
Thu Jan 14 21:35:23 UTC 2021


        at  5f40f3d3559ba3705c3a788d84e33ff8221bd0bd (commit)


commit 5f40f3d3559ba3705c3a788d84e33ff8221bd0bd
Author: Lucas Di Pentima <lucas at di-pentima.com.ar>
Date:   Thu Jan 14 18:34:35 2021 -0300

    17109: Adds support for inline keep-web PDH URLs.
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas at di-pentima.com.ar>

diff --git a/src/views-components/context-menu/actions/helpers.test.ts b/src/views-components/context-menu/actions/helpers.test.ts
index c3a31691..b2cb4a55 100644
--- a/src/views-components/context-menu/actions/helpers.test.ts
+++ b/src/views-components/context-menu/actions/helpers.test.ts
@@ -6,7 +6,8 @@ import { sanitizeToken, getClipboardUrl, getInlineFileUrl } from "./helpers";
 
 describe('helpers', () => {
     // given
-    const url = 'https://example.com/c=zzzzz/t=v2/a/b/LIMS/1.html';
+    const url = 'https://example.com/c=zzzzz-4zz18-0123456789abcde/t=v2/a/b/LIMS/1.html';
+    const urlWithPdh = 'https://example.com/c=012345678901234567890123456789aa+0/t=v2/a/b/LIMS/1.html';
 
     describe('sanitizeToken', () => {
         it('should sanitize token from the url', () => {
@@ -14,7 +15,7 @@ describe('helpers', () => {
             const result = sanitizeToken(url);
 
             // then
-            expect(result).toBe('https://example.com/c=zzzzz/LIMS/1.html?api_token=v2/a/b');
+            expect(result).toBe('https://example.com/c=zzzzz-4zz18-0123456789abcde/LIMS/1.html?api_token=v2/a/b');
         });
     });
 
@@ -24,7 +25,7 @@ describe('helpers', () => {
             const result = getClipboardUrl(url);
 
             // then
-            expect(result).toBe('http://localhost?redirectTo=https://example.com/c=zzzzz/LIMS/1.html');
+            expect(result).toBe('http://localhost?redirectTo=https://example.com/c=zzzzz-4zz18-0123456789abcde/LIMS/1.html');
         });
     });
 
@@ -37,9 +38,13 @@ describe('helpers', () => {
 
             // then
             expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlA))
-                .toBe('https://zzzzz.collections.example.com/t=v2/a/b/LIMS/1.html');
+                .toBe('https://zzzzz-4zz18-0123456789abcde.collections.example.com/t=v2/a/b/LIMS/1.html');
             expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlB))
-                .toBe('https://zzzzz--collections.example.com/t=v2/a/b/LIMS/1.html');
+                .toBe('https://zzzzz-4zz18-0123456789abcde--collections.example.com/t=v2/a/b/LIMS/1.html');
+            expect(getInlineFileUrl(urlWithPdh, webDavDownloadUrl, webDavUrlA))
+                .toBe('https://012345678901234567890123456789aa-0.collections.example.com/t=v2/a/b/LIMS/1.html');
+            expect(getInlineFileUrl(urlWithPdh, webDavDownloadUrl, webDavUrlB))
+                .toBe('https://012345678901234567890123456789aa-0--collections.example.com/t=v2/a/b/LIMS/1.html');
         });
 
         it('should keep the url the same when no inline url available', () => {
@@ -49,7 +54,7 @@ describe('helpers', () => {
             const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl);
 
             // then
-            expect(result).toBe('https://example.com/c=zzzzz/t=v2/a/b/LIMS/1.html');
+            expect(result).toBe('https://example.com/c=zzzzz-4zz18-0123456789abcde/t=v2/a/b/LIMS/1.html');
         });
 
         it('should replace the url when available', () => {
@@ -59,7 +64,7 @@ describe('helpers', () => {
             const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl);
 
             // then
-            expect(result).toBe('https://download.example.com/c=zzzzz/t=v2/a/b/LIMS/1.html');
+            expect(result).toBe('https://download.example.com/c=zzzzz-4zz18-0123456789abcde/t=v2/a/b/LIMS/1.html');
         });
     });
 });
\ No newline at end of file
diff --git a/src/views-components/context-menu/actions/helpers.ts b/src/views-components/context-menu/actions/helpers.ts
index ce5dd8b1..261f5a87 100644
--- a/src/views-components/context-menu/actions/helpers.ts
+++ b/src/views-components/context-menu/actions/helpers.ts
@@ -2,6 +2,8 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+import { extractUuidKind, ResourceKind } from "~/models/resource";
+
 export const sanitizeToken = (href: string, tokenAsQueryParam = true): string => {
     const [prefix, suffix] = href.split('/t=');
     const [token1, token2, token3, ...rest] = suffix.split('/');
@@ -19,9 +21,10 @@ export const getClipboardUrl = (href: string, shouldSanitizeToken = true): strin
 };
 
 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];
+    const collMatch = url.match(/\/c=([a-z0-9-+]+)\//);
+    if (collMatch === null) { return ''; }
+    if (extractUuidKind(collMatch[1]) !== ResourceKind.COLLECTION) { return ''; }
+    const collId = collMatch[1].replace('+', '-');
     let inlineUrl = keepWebInlineSvcUrl !== ""
         ? url.replace(keepWebSvcUrl, keepWebInlineSvcUrl)
         : url;
@@ -30,14 +33,14 @@ export const getInlineFileUrl = (url: string, keepWebSvcUrl: string, keepWebInli
     // '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}.`);
+        inlineUrl = inlineUrl.replace('*.', `${collId}.`);
         uuidOnHostname = true;
     } else if (inlineUrl.indexOf('*--') > -1) {
-        inlineUrl = inlineUrl.replace('*--', `${collUuid}--`);
+        inlineUrl = inlineUrl.replace('*--', `${collId}--`);
         uuidOnHostname = true;
     }
     if (uuidOnHostname) {
-        inlineUrl = inlineUrl.replace(`/c=${collUuid}`, '');
+        inlineUrl = inlineUrl.replace(`/c=${collMatch[1]}`, '');
     }
     return inlineUrl;
 };
\ No newline at end of file

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list