Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/api/src/common/files.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path'
import { UnsupportedMediaTypeException } from '@nestjs/common'

interface File {
fieldname: string
Expand Down Expand Up @@ -34,7 +35,7 @@ export function validateFileType(
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
]
if (!mimeAllowlist.includes(file.mimetype)) {
return cb(new Error('File mime type is not allowed'), false)
return cb(new UnsupportedMediaTypeException('File mime type is not allowed'), false)
}

const allowedExtensions = /txt|json|pdf|jpeg|jpg|png|xml|xlsx|xls|docx/
Expand All @@ -47,7 +48,10 @@ export function validateFileType(
}
const isExtensionSupported = allowedExtensions.test(ext)
if (!isExtensionSupported) {
return cb(new Error('File extension is not allowed: ' + file.filename), false)
return cb(
new UnsupportedMediaTypeException('File extension is not allowed: ' + file.filename),
false,
)
}

cb(null, true)
Expand Down
Loading