diff --git a/src/shared/components/ImagePreview/ImagePreview.tsx b/src/shared/components/ImagePreview/ImagePreview.tsx index 43ea7a519..996e541ba 100644 --- a/src/shared/components/ImagePreview/ImagePreview.tsx +++ b/src/shared/components/ImagePreview/ImagePreview.tsx @@ -114,7 +114,7 @@ const fetchImageResources = async ({ const rawData = await nexus.File.get( orgLabel, projectLabel, - parseResourceId(contentUrl), + encodeURIComponent(decodeURIComponent(contentUrl)), { as: 'blob' } ); const blob = new Blob([rawData as string], { diff --git a/src/shared/components/Preview/Preview.tsx b/src/shared/components/Preview/Preview.tsx index 00a264d2a..06f802322 100644 --- a/src/shared/components/Preview/Preview.tsx +++ b/src/shared/components/Preview/Preview.tsx @@ -244,14 +244,14 @@ const Preview: React.FC<{ contentUrl = url; options.rev = parseInt(rev, 10); } + try { const rawData = await nexus.File.get( orgLabel, projectLabel, - encodeURIComponent(contentUrl), + encodeURIComponent(decodeURIComponent(contentUrl)), options ); - downloadBlobHelper(rawData, asset.name); } catch (error) { notification.error({ diff --git a/src/shared/components/ResourceEditor/ResourcesLRUCache.ts b/src/shared/components/ResourceEditor/ResourcesLRUCache.ts index 698bdf927..63baeef9f 100644 --- a/src/shared/components/ResourceEditor/ResourcesLRUCache.ts +++ b/src/shared/components/ResourceEditor/ResourcesLRUCache.ts @@ -4,6 +4,16 @@ import LRUCache from 'lru-cache'; // TODO: Use nexus.httpGet to prepare for using http cache headers // since the nexus SDK can not accept the headers as an argument + +const parseResourceId = (url: string) => { + const fileUrlPattern = /files\/([\w-]+)\/([\w-]+)\/(.*)/; + if (fileUrlPattern.test(url)) { + const [, , , resourceId] = url.match(fileUrlPattern) as string[]; + return decodeURIComponent(resourceId.split('?rev=')[0]); + } + return decodeURIComponent(url); +}; + const lookByProjectResolver = async ({ nexus, apiEndpoint, @@ -18,7 +28,9 @@ const lookByProjectResolver = async ({ resourceId: string; }): Promise => { return await nexus.httpGet({ - path: `${apiEndpoint}/resolvers/${orgLabel}/${projectLabel}/_/${resourceId}`, + path: `${apiEndpoint}/resolvers/${orgLabel}/${projectLabel}/_/${encodeURIComponent( + parseResourceId(resourceId) + )}`, }); }; const lookBySearchApi = async ({ @@ -31,7 +43,9 @@ const lookBySearchApi = async ({ resourceId: string; }): Promise => { return await nexus.httpGet({ - path: `${apiEndpoint}/resources?locate=${resourceId}`, + path: `${apiEndpoint}/resources?locate=${encodeURIComponent( + parseResourceId(resourceId) + )}`, }); }; diff --git a/src/shared/components/ResourceEditor/editorUtils.ts b/src/shared/components/ResourceEditor/editorUtils.ts index 28448bd43..61f04fa56 100644 --- a/src/shared/components/ResourceEditor/editorUtils.ts +++ b/src/shared/components/ResourceEditor/editorUtils.ts @@ -174,7 +174,7 @@ export async function editorLinkResolutionHandler({ apiEndpoint, orgLabel, projectLabel, - resourceId: encodeURIComponent(url), + resourceId: url, }, })); } diff --git a/src/shared/components/ResourceEditor/useResolutionActions.tsx b/src/shared/components/ResourceEditor/useResolutionActions.tsx index 5512a1260..09bd7973c 100644 --- a/src/shared/components/ResourceEditor/useResolutionActions.tsx +++ b/src/shared/components/ResourceEditor/useResolutionActions.tsx @@ -76,7 +76,7 @@ const useResolvedLinkEditorPopover = () => { const data = await nexus.File.get( orgLabel, projectLabel, - encodeURIComponent(parseResourceId(resourceId)), + encodeURIComponent(decodeURIComponent(parseResourceId(resourceId))), { as: 'blob' } ); return download(title, ext ?? 'json', data); diff --git a/src/shared/containers/AnalysisPlugin/AnalysisPluginContainer.tsx b/src/shared/containers/AnalysisPlugin/AnalysisPluginContainer.tsx index 803866589..f0232f320 100644 --- a/src/shared/containers/AnalysisPlugin/AnalysisPluginContainer.tsx +++ b/src/shared/containers/AnalysisPlugin/AnalysisPluginContainer.tsx @@ -41,7 +41,7 @@ async function fetchImageObjectUrl( const rawData = await nexus.File.get( orgLabel, projectLabel, - encodeURIComponent(imageResourceId), + encodeURIComponent(decodeURIComponent(imageResourceId)), { as: 'blob', } diff --git a/src/shared/containers/ResourceActionsContainer.tsx b/src/shared/containers/ResourceActionsContainer.tsx index 9ea3c0c35..d19e1d477 100644 --- a/src/shared/containers/ResourceActionsContainer.tsx +++ b/src/shared/containers/ResourceActionsContainer.tsx @@ -154,12 +154,15 @@ const ResourceActionsContainer: React.FunctionComponent<{ }, downloadFile: async () => { try { - const data = await nexus.File.get( - orgLabel, - projectLabel, - parseResourceId(resource._self), - { as: 'blob' } - ); + const data = await nexus.httpGet({ + path: resource._self, + headers: { + Accept: 'application/json', + }, + context: { + as: 'blob', + }, + }); return download( resource._filename || getResourceLabel(resource), resource._mediaType, diff --git a/src/shared/containers/TableViewerContainer.tsx b/src/shared/containers/TableViewerContainer.tsx index 687835413..67e934ab7 100644 --- a/src/shared/containers/TableViewerContainer.tsx +++ b/src/shared/containers/TableViewerContainer.tsx @@ -27,7 +27,7 @@ const TableViewerContainer: React.FC<{ await nexus.File.get( orgLabel, projectLabel, - encodeURIComponent(resourceId), + encodeURIComponent(decodeURIComponent(resourceId)), { as: 'text', }