Skip to content

Commit

Permalink
ref: refactor nexusUrlHardEncode
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalesi committed Jul 25, 2023
1 parent 1aeacce commit 7a035ba
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/shared/components/ImagePreview/ImagePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import {
SortDescendingOutlined,
DownloadOutlined,
} from '@ant-design/icons';
import { orderBy, isNil, create, isArray, isObject } from 'lodash';
import { orderBy, isNil, isArray, isObject } from 'lodash';
import { parseProjectUrl, parseResourceId } from '../Preview/Preview';
import nexusUrlHardEncode from '../../utils/nexusEncode';

import './ImagePreview.less';

Expand Down Expand Up @@ -114,7 +115,7 @@ const fetchImageResources = async ({
const rawData = await nexus.File.get(
orgLabel,
projectLabel,
encodeURIComponent(decodeURIComponent(contentUrl)),
nexusUrlHardEncode(contentUrl),
{ as: 'blob' }
);
const blob = new Blob([rawData as string], {
Expand Down
3 changes: 2 additions & 1 deletion src/shared/components/Preview/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useNotification from '../../hooks/useNotification';
import TableViewerContainer from '../../containers/TableViewerContainer';
import { useSelector } from 'react-redux';
import { RootState } from '../../store/reducers';
import nexusUrlHardEncode from '../../utils/nexusEncode';

export const parseResourceId = (url: string) => {
const fileUrlPattern = /files\/([\w-]+)\/([\w-]+)\/(.*)/;
Expand Down Expand Up @@ -249,7 +250,7 @@ const Preview: React.FC<{
const rawData = await nexus.File.get(
orgLabel,
projectLabel,
encodeURIComponent(decodeURIComponent(contentUrl)),
nexusUrlHardEncode(contentUrl),
options
);
downloadBlobHelper(rawData, asset.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { parseResourceId } from '../Preview/Preview';
import { download } from '../../utils/download';
import { getDataExplorerResourceItemArray } from './editorUtils';
import nexusUrlHardEncode from '../../utils/nexusEncode';

const useResolvedLinkEditorPopover = () => {
const nexus = useNexusContext();
Expand Down Expand Up @@ -76,7 +77,7 @@ const useResolvedLinkEditorPopover = () => {
const data = await nexus.File.get(
orgLabel,
projectLabel,
encodeURIComponent(decodeURIComponent(parseResourceId(resourceId))),
nexusUrlHardEncode(parseResourceId(resourceId)),
{ as: 'blob' }
);
return download(title, ext ?? 'json', data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
AnalysisAssetSparqlQueryRowResult,
ReportGeneration,
} from '../../types/plugins/report';
import useNotification from '../../../shared/hooks/useNotification';
import useNotification from '../../hooks/useNotification';
import nexusUrlHardEncode from '../../utils/nexusEncode';

async function fetchImageObjectUrl(
nexus: NexusClient,
Expand All @@ -41,7 +42,7 @@ async function fetchImageObjectUrl(
const rawData = await nexus.File.get(
orgLabel,
projectLabel,
encodeURIComponent(decodeURIComponent(imageResourceId)),
nexusUrlHardEncode(imageResourceId),
{
as: 'blob',
}
Expand Down
5 changes: 3 additions & 2 deletions src/shared/containers/TableViewerContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import * as csvParser from 'csv-string';

import TableViewer from '../components/TableViewer';
import useNotification from '../hooks/useNotification';
import { parseResourceId } from '../../shared/components/Preview/Preview';
import { parseResourceId } from '../components/Preview/Preview';
import nexusUrlHardEncode from '../utils/nexusEncode';

const TableViewerContainer: React.FC<{
resourceUrl: string;
Expand All @@ -27,7 +28,7 @@ const TableViewerContainer: React.FC<{
await nexus.File.get(
orgLabel,
projectLabel,
encodeURIComponent(decodeURIComponent(resourceId)),
nexusUrlHardEncode(resourceId),
{
as: 'text',
}
Expand Down
5 changes: 5 additions & 0 deletions src/shared/utils/nexusEncode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const nexusUrlHardEncode = (url: string): string => {
return encodeURIComponent(decodeURIComponent(url));
};

export default nexusUrlHardEncode;

0 comments on commit 7a035ba

Please sign in to comment.