aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/videos.ts6
-rw-r--r--server/helpers/express-utils.ts9
-rw-r--r--server/helpers/video.ts19
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
83function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { 83function 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
91const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME 87const 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'
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
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 @@
1import { VideoModel } from '../models/video/video'
2import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { Response } from 'express'
3import { CONFIG } from '@server/initializers/config'
4import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants'
5import { JobQueue } from '@server/lib/job-queue'
3import { 6import {
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'
15import { Response } from 'express'
16import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants'
17import { JobQueue } from '@server/lib/job-queue'
18import { VideoPrivacy, VideoTranscodingPayload } from '@shared/models' 18import { VideoPrivacy, VideoTranscodingPayload } from '@shared/models'
19import { CONFIG } from "@server/initializers/config" 19import { VideoModel } from '../models/video/video'
20 20
21type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' 21type 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
113function 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
113export { 121export {
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}