Skip to content

Commit

Permalink
feat: allow more file types to upload
Browse files Browse the repository at this point in the history
It will still restrict a subset of types such as zip, rar, tar etc
  • Loading branch information
bjarneo committed Aug 21, 2022
1 parent f9d3b4b commit ddbdb01
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/client/routes/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ const Home = () => {
{enableFileUpload && (
<FileButton
onChange={setFile}
accept="image/*,application/pdf"
accept="image/*,text/*,application/*"
disabled={!isLoggedIn}
>
{(props) => (
<Button
{...props}
label={!isLoggedIn ? 'Sign in to upload images' : ''}
label={!isLoggedIn ? 'Sign in to upload files' : ''}
styles={() => ({
root: {
backgroundColor: 'var(--color-contrast)',
Expand All @@ -286,15 +286,15 @@ const Home = () => {
},
})}
>
Upload image
Upload file
</Button>
)}
</FileButton>
)}

{enableFileUpload && !isLoggedIn && (
<Text size="sm" align="center" mt="sm">
Sign in to upload images
Sign in to upload files
</Text>
)}

Expand Down
2 changes: 1 addition & 1 deletion src/client/routes/secret/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const Secret = () => {
disabled={!secretId}
leftIcon={<IconDownload size={14} />}
>
Download the secret file
Download file
</Button>
)}

Expand Down
25 changes: 24 additions & 1 deletion src/server/decorators/attachment-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,35 @@ const FileType = require('file-type');
const MAX_FILE_BYTES = 1024 * 16 * 1000; // 16mb - 16 024 000 bytes
const { upload } = require('../services/do');

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
const notAllowed = [
'application/zip',
'application/x-7z-compressed',
'application/x-tar',
'application/vnd.rar',
'application/ogg',
'application/java-archive',
'application/gzip',
'application/x-bzip2',
'application/x-bzip',
'application/x-cdf',
'application/x-freearc',
];

function acceptedFileType(file) {
if (notAllowed.indexOf(file.mimetype) > -1) {
return false;
}

if (file.mimetype.startsWith('image/')) {
return true;
}

if (file.mimetype.startsWith('application/pdf')) {
if (file.mimetype.startsWith('application/')) {
return true;
}

if (file.mimetype.startsWith('text/')) {
return true;
}

Expand Down

0 comments on commit ddbdb01

Please sign in to comment.