Skip to content

Commit

Permalink
chore: allow .txt .svg .md and so on
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarneo committed Aug 30, 2022
1 parent 6558a15 commit 8d79ddd
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 95 deletions.
149 changes: 57 additions & 92 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -47,7 +47,7 @@
"fastify": "^4.5.3",
"fastify-jwt": "^3.0.0",
"fastify-plugin": "^3.0.0",
"file-type": "^16.5.4",
"file-type": "^18.0.0",
"is-base64": "^1.1.0",
"is-ip": "^3.1.0",
"nanoid": "^3.1.31",
Expand Down
9 changes: 7 additions & 2 deletions src/server/decorators/attachment-upload.js
@@ -1,5 +1,7 @@
import path from 'path';
import validator from 'validator';
import fp from 'fastify-plugin';
import FileType from 'file-type';
import { fileTypeFromBuffer } from 'file-type';

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

Expand Down Expand Up @@ -46,7 +48,10 @@ export default fp(async (fastify) => {
if (file.mimetype) {
const fileData = await file.toBuffer();

const { ext, mime } = await FileType.fromBuffer(fileData);
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({
Expand Down

0 comments on commit 8d79ddd

Please sign in to comment.