19700: Detect http/s input files and display as link
authorStephen Smith <stephen@curii.com>
Thu, 1 Dec 2022 16:13:16 +0000 (11:13 -0500)
committerStephen Smith <stephen@curii.com>
Thu, 1 Dec 2022 16:13:16 +0000 (11:13 -0500)
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen@curii.com>

src/models/resource.ts
src/views/process-panel/process-io-card.tsx

index fd86727782c2960b15ee78d4237da4dcc53363b4..2d2b9f210141e27c20d4ae284bbec9a79899dee8 100644 (file)
@@ -67,6 +67,7 @@ export const RESOURCE_UUID_PATTERN = '[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}';
 export const PORTABLE_DATA_HASH_PATTERN = '[a-f0-9]{32}\\+\\d+';
 export const RESOURCE_UUID_REGEX = new RegExp("^" + RESOURCE_UUID_PATTERN + "$");
 export const COLLECTION_PDH_REGEX = new RegExp("^" + PORTABLE_DATA_HASH_PATTERN + "$");
+export const KEEP_URL_REGEX = new RegExp("^(keep:)?" + PORTABLE_DATA_HASH_PATTERN);
 
 export const isResourceUuid = (uuid: string) =>
     RESOURCE_UUID_REGEX.test(uuid);
index 4f93f48c2e75552134514a1165eb38f11c8aad6b..14a6eae273a195e143dd6bc0533e02b5bbd942f4 100644 (file)
@@ -74,6 +74,7 @@ import { Process } from 'store/processes/process';
 import { navigateTo } from 'store/navigation/navigation-action';
 import classNames from 'classnames';
 import { DefaultCodeSnippet } from 'components/default-code-snippet/default-code-snippet';
+import { KEEP_URL_REGEX } from 'models/resource';
 
 type CssRules =
   | "card"
@@ -657,6 +658,11 @@ const isFileImage = (basename?: string): boolean => {
     return basename ? (mime.getType(basename) || "").startsWith('image/') : false;
 };
 
+const isFileUrl = (location?: string): boolean => (
+    !!location && !KEEP_URL_REGEX.exec(location) &&
+    (location.startsWith("http://") || location.startsWith("https://"))
+);
+
 const normalizeDirectoryLocation = (directory: Directory): Directory => {
     if (!directory.location) {
         return directory;
@@ -680,6 +686,13 @@ const directoryToProcessIOValue = (directory: Directory, auth: AuthState, pdh?:
 const fileToProcessIOValue = (file: File, secondary: boolean, auth: AuthState, pdh: string | undefined, mainFilePdh: string): ProcessIOValue => {
     if (isExternalValue(file)) {return {display: <UnsupportedValue />}}
 
+    if (isFileUrl(file.location)) {
+        return {
+            display: <MuiLink href={file.location} target="_blank">{file.location}</MuiLink>,
+            secondary,
+        };
+    }
+
     const resourcePdh = getResourcePdhUrl(file, pdh);
     return {
         display: <KeepUrlPath auth={auth} res={file} pdh={pdh}/>,