diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 6 | ||||
-rw-r--r-- | server/helpers/express-utils.ts | 9 | ||||
-rw-r--r-- | server/helpers/video.ts | 19 |
3 files changed, 20 insertions, 14 deletions
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 60e8075f6..40fecc09b 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -81,11 +81,7 @@ function isVideoFileExtnameValid (value: string) { | |||
81 | } | 81 | } |
82 | 82 | ||
83 | function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { | 83 | function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { |
84 | const videoFileTypesRegex = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT) | 84 | return isFileValid(files, MIMETYPES.VIDEO.MIMETYPES_REGEX, 'videofile', null) |
85 | .map(m => `(${m})`) | ||
86 | .join('|') | ||
87 | |||
88 | return isFileValid(files, videoFileTypesRegex, 'videofile', null) | ||
89 | } | 85 | } |
90 | 86 | ||
91 | const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME | 87 | const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME |
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 | ||
diff --git a/server/helpers/video.ts b/server/helpers/video.ts index 89c85accb..488b4da17 100644 --- a/server/helpers/video.ts +++ b/server/helpers/video.ts | |||
@@ -1,5 +1,8 @@ | |||
1 | import { VideoModel } from '../models/video/video' | ||
2 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { Response } from 'express' | ||
3 | import { CONFIG } from '@server/initializers/config' | ||
4 | import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants' | ||
5 | import { JobQueue } from '@server/lib/job-queue' | ||
3 | import { | 6 | import { |
4 | isStreamingPlaylist, | 7 | isStreamingPlaylist, |
5 | MStreamingPlaylistVideo, | 8 | MStreamingPlaylistVideo, |
@@ -12,11 +15,8 @@ import { | |||
12 | MVideoThumbnail, | 15 | MVideoThumbnail, |
13 | MVideoWithRights | 16 | MVideoWithRights |
14 | } from '@server/types/models' | 17 | } from '@server/types/models' |
15 | import { Response } from 'express' | ||
16 | import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants' | ||
17 | import { JobQueue } from '@server/lib/job-queue' | ||
18 | import { VideoPrivacy, VideoTranscodingPayload } from '@shared/models' | 18 | import { VideoPrivacy, VideoTranscodingPayload } from '@shared/models' |
19 | import { CONFIG } from "@server/initializers/config" | 19 | import { VideoModel } from '../models/video/video' |
20 | 20 | ||
21 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' | 21 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' |
22 | 22 | ||
@@ -110,6 +110,14 @@ function getPrivaciesForFederation () { | |||
110 | : [ { privacy: VideoPrivacy.PUBLIC } ] | 110 | : [ { privacy: VideoPrivacy.PUBLIC } ] |
111 | } | 111 | } |
112 | 112 | ||
113 | function getExtFromMimetype (mimeTypes: { [id: string]: string | string[] }, mimeType: string) { | ||
114 | const value = mimeTypes[mimeType] | ||
115 | |||
116 | if (Array.isArray(value)) return value[0] | ||
117 | |||
118 | return value | ||
119 | } | ||
120 | |||
113 | export { | 121 | export { |
114 | VideoFetchType, | 122 | VideoFetchType, |
115 | VideoFetchByUrlType, | 123 | VideoFetchByUrlType, |
@@ -118,6 +126,7 @@ export { | |||
118 | fetchVideoByUrl, | 126 | fetchVideoByUrl, |
119 | addOptimizeOrMergeAudioJob, | 127 | addOptimizeOrMergeAudioJob, |
120 | extractVideo, | 128 | extractVideo, |
129 | getExtFromMimetype, | ||
121 | isPrivacyForFederation, | 130 | isPrivacyForFederation, |
122 | getPrivaciesForFederation | 131 | getPrivaciesForFederation |
123 | } | 132 | } |