aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/express-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/express-utils.ts')
-rw-r--r--server/helpers/express-utils.ts9
1 files changed, 5 insertions, 4 deletions
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts
index f46812977..ba23557ba 100644
--- a/server/helpers/express-utils.ts
+++ b/server/helpers/express-utils.ts
@@ -6,6 +6,7 @@ import { deleteFileAsync, generateRandomString } from './utils'
6import { extname } from 'path' 6import { extname } from 'path'
7import { isArray } from './custom-validators/misc' 7import { isArray } from './custom-validators/misc'
8import { CONFIG } from '../initializers/config' 8import { CONFIG } from '../initializers/config'
9import { getExtFromMimetype } from './video'
9 10
10function buildNSFWFilter (res?: express.Response, paramNSFW?: string) { 11function buildNSFWFilter (res?: express.Response, paramNSFW?: string) {
11 if (paramNSFW === 'true') return true 12 if (paramNSFW === 'true') return true
@@ -65,7 +66,7 @@ function badRequest (req: express.Request, res: express.Response) {
65 66
66function createReqFiles ( 67function createReqFiles (
67 fieldNames: string[], 68 fieldNames: string[],
68 mimeTypes: { [id: string]: string }, 69 mimeTypes: { [id: string]: string | string[] },
69 destinations: { [fieldName: string]: string } 70 destinations: { [fieldName: string]: string }
70) { 71) {
71 const storage = multer.diskStorage({ 72 const storage = multer.diskStorage({
@@ -76,13 +77,13 @@ function createReqFiles (
76 filename: async (req, file, cb) => { 77 filename: async (req, file, cb) => {
77 let extension: string 78 let extension: string
78 const fileExtension = extname(file.originalname) 79 const fileExtension = extname(file.originalname)
79 const extensionFromMimetype = mimeTypes[file.mimetype] 80 const extensionFromMimetype = getExtFromMimetype(mimeTypes, file.mimetype)
80 81
81 // Take the file extension if we don't understand the mime type 82 // Take the file extension if we don't understand the mime type
82 // We have the OGG/OGV exception too because firefox sends a bad mime type when sending an OGG file 83 if (!extensionFromMimetype) {
83 if (fileExtension === '.ogg' || fileExtension === '.ogv' || !extensionFromMimetype) {
84 extension = fileExtension 84 extension = fileExtension
85 } else { 85 } else {
86 // Take the first available extension for this mimetype
86 extension = extensionFromMimetype 87 extension = extensionFromMimetype
87 } 88 }
88 89