Skip to content

Commit

Permalink
feat: allow all kinds of files
Browse files Browse the repository at this point in the history
fingers crossed here
  • Loading branch information
bjarneo committed Aug 30, 2022
1 parent 5a767f0 commit 015ccb8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 47 deletions.
6 changes: 1 addition & 5 deletions src/client/routes/home/index.js
Expand Up @@ -358,11 +358,7 @@ const Home = () => {

<Group grow={isMobile}>
{enableFileUpload && (
<FileButton
onChange={setFile}
accept="image/*,text/*,application/*"
disabled={!isLoggedIn}
>
<FileButton onChange={setFile} disabled={!isLoggedIn}>
{(props) => (
<Button
{...props}
Expand Down
43 changes: 1 addition & 42 deletions src/server/decorators/attachment-upload.js
Expand Up @@ -4,41 +4,6 @@ import { fileTypeFromBuffer } from 'file-type';

import fileAdapter from '../services/file-adapter.js';

// 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(mimetype) {
if (notAllowed.indexOf(mimetype) > -1) {
return false;
}

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

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

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

return false;
}

export default fp(async (fastify) => {
fastify.decorate('attachment', async (req, reply) => {
const file = await req.body.file;
Expand All @@ -50,13 +15,7 @@ export default fp(async (fastify) => {
const metadata = await fileTypeFromBuffer(fileData);

const mime = metadata?.mime ? metadata.mime : file.mimetype.toString();
const ext = metadata?.ext ? metadata.ext : path.extname(file.filename);

if (!acceptedFileType(mime)) {
return reply.code(415).send({
error: `This file type "${mime}" is not supported, yet.`,
});
}
const ext = metadata?.ext ? metadata.ext : path.extname(file.filename).replace('.', '');

const imageData = await fileAdapter.upload(encryptionKey, fileData);

Expand Down

0 comments on commit 015ccb8

Please sign in to comment.