aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/index.ts27
1 files changed, 3 insertions, 24 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 11e3da5cc..ff0d967e1 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -6,7 +6,7 @@ import { renamePromise } from '../../../helpers/core-utils'
6import { retryTransactionWrapper } from '../../../helpers/database-utils' 6import { retryTransactionWrapper } from '../../../helpers/database-utils'
7import { getVideoFileHeight } from '../../../helpers/ffmpeg-utils' 7import { getVideoFileHeight } from '../../../helpers/ffmpeg-utils'
8import { logger } from '../../../helpers/logger' 8import { logger } from '../../../helpers/logger'
9import { generateRandomString, getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils' 9import { createReqFiles, generateRandomString, getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils'
10import { 10import {
11 CONFIG, sequelizeTypescript, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, 11 CONFIG, sequelizeTypescript, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT,
12 VIDEO_PRIVACIES 12 VIDEO_PRIVACIES
@@ -29,28 +29,7 @@ import { rateVideoRouter } from './rate'
29 29
30const videosRouter = express.Router() 30const videosRouter = express.Router()
31 31
32// multer configuration 32const reqVideoFile = createReqFiles('videofile', CONFIG.STORAGE.VIDEOS_DIR, VIDEO_MIMETYPE_EXT)
33const storage = multer.diskStorage({
34 destination: (req, file, cb) => {
35 cb(null, CONFIG.STORAGE.VIDEOS_DIR)
36 },
37
38 filename: async (req, file, cb) => {
39 const extension = VIDEO_MIMETYPE_EXT[file.mimetype]
40 let randomString = ''
41
42 try {
43 randomString = await generateRandomString(16)
44 } catch (err) {
45 logger.error('Cannot generate random string for file name.', err)
46 randomString = 'fake-random-string'
47 }
48
49 cb(null, randomString + extension)
50 }
51})
52
53const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }])
54 33
55videosRouter.use('/', abuseVideoRouter) 34videosRouter.use('/', abuseVideoRouter)
56videosRouter.use('/', blacklistRouter) 35videosRouter.use('/', blacklistRouter)
@@ -85,7 +64,7 @@ videosRouter.put('/:id',
85) 64)
86videosRouter.post('/upload', 65videosRouter.post('/upload',
87 authenticate, 66 authenticate,
88 reqFiles, 67 reqVideoFile,
89 asyncMiddleware(videosAddValidator), 68 asyncMiddleware(videosAddValidator),
90 asyncMiddleware(addVideoRetryWrapper) 69 asyncMiddleware(addVideoRetryWrapper)
91) 70)