From c5911fd347c76e8bdc05ea9f3ee9efed4a58c236 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 Dec 2017 19:10:13 +0100 Subject: Begin to add avatar to actors --- server/controllers/api/videos/index.ts | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'server/controllers/api/videos') 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' import { retryTransactionWrapper } from '../../../helpers/database-utils' import { getVideoFileHeight } from '../../../helpers/ffmpeg-utils' import { logger } from '../../../helpers/logger' -import { generateRandomString, getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils' +import { createReqFiles, generateRandomString, getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils' import { CONFIG, sequelizeTypescript, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES @@ -29,28 +29,7 @@ import { rateVideoRouter } from './rate' const videosRouter = express.Router() -// multer configuration -const storage = multer.diskStorage({ - destination: (req, file, cb) => { - cb(null, CONFIG.STORAGE.VIDEOS_DIR) - }, - - filename: async (req, file, cb) => { - const extension = VIDEO_MIMETYPE_EXT[file.mimetype] - let randomString = '' - - try { - randomString = await generateRandomString(16) - } catch (err) { - logger.error('Cannot generate random string for file name.', err) - randomString = 'fake-random-string' - } - - cb(null, randomString + extension) - } -}) - -const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) +const reqVideoFile = createReqFiles('videofile', CONFIG.STORAGE.VIDEOS_DIR, VIDEO_MIMETYPE_EXT) videosRouter.use('/', abuseVideoRouter) videosRouter.use('/', blacklistRouter) @@ -85,7 +64,7 @@ videosRouter.put('/:id', ) videosRouter.post('/upload', authenticate, - reqFiles, + reqVideoFile, asyncMiddleware(videosAddValidator), asyncMiddleware(addVideoRetryWrapper) ) -- cgit v1.2.3