Skip to content

Commit

Permalink
Check that path contains file extension before using (#984)
Browse files Browse the repository at this point in the history
Co-authored-by: Dhanesh Neela Mana <[email protected]>
  • Loading branch information
nicwells and Dhanesh Neela Mana authored Oct 25, 2021
1 parent 74a70fe commit fbd4bac
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/shared/components/Preview/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const parseProjectUrl = (projectUrl: string) => {
return [org, proj];
};

const isSupportedFile = (asset: any) =>
asset.encodingFormat === 'application/pdf' ||
asset.name?.endsWith('.csv') ||
asset.name?.endsWith('.tsv');

const Preview: React.FC<{
resource: Resource;
nexus: NexusClient;
Expand Down Expand Up @@ -63,7 +68,12 @@ const Preview: React.FC<{
}) => {
return (
<>
<Button onClick={() => setPreviewAsset(asset)}>Preview</Button>
<Button
onClick={() => setPreviewAsset(asset)}
disabled={!isSupportedFile(asset)}
>
Preview
</Button>
<Button onClick={() => copyURI(asset.url)}>Copy URI</Button>
<Button
onClick={() => download(nexus, orgLabel, projectLabel, asset)}
Expand Down Expand Up @@ -155,7 +165,9 @@ const Preview: React.FC<{
name: d.name,
encodingFormat: d.encodingFormat,
},
encodingFormat: d.encodingFormat || d.name.split('.').pop() || '-',
encodingFormat:
d.encodingFormat ||
(d.name?.includes('.') ? d.name.split('.').pop() : '-'),
contentSize: d.contentSize,
};
})
Expand All @@ -165,7 +177,10 @@ const Preview: React.FC<{
return data;
};

const fileFormat = previewAsset && previewAsset.name.split('.').pop();
const fileFormat =
previewAsset && previewAsset.name?.includes('.')
? previewAsset.name.split('.').pop()
: '-';

return (
<div>
Expand Down

0 comments on commit fbd4bac

Please sign in to comment.