diff options
author | Chocobozzz <me@florianbigard.com> | 2020-08-10 14:25:29 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-08-11 07:57:20 +0200 |
commit | 30bc55c88b3b7416c2224925e88639694fd32746 (patch) | |
tree | aebe3b1b8657198e432080f7d15a5694f19a8389 /server/helpers/express-utils.ts | |
parent | 560605026bfadab711cf6d34e9c7ea865887816a (diff) | |
download | PeerTube-30bc55c88b3b7416c2224925e88639694fd32746.tar.gz PeerTube-30bc55c88b3b7416c2224925e88639694fd32746.tar.zst PeerTube-30bc55c88b3b7416c2224925e88639694fd32746.zip |
Refactor video extensions logic in server
Diffstat (limited to 'server/helpers/express-utils.ts')
-rw-r--r-- | server/helpers/express-utils.ts | 9 |
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' | |||
6 | import { extname } from 'path' | 6 | import { extname } from 'path' |
7 | import { isArray } from './custom-validators/misc' | 7 | import { isArray } from './custom-validators/misc' |
8 | import { CONFIG } from '../initializers/config' | 8 | import { CONFIG } from '../initializers/config' |
9 | import { getExtFromMimetype } from './video' | ||
9 | 10 | ||
10 | function buildNSFWFilter (res?: express.Response, paramNSFW?: string) { | 11 | function 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 | ||
66 | function createReqFiles ( | 67 | function 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 | ||