aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/api/v1/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'routes/api/v1/videos.js')
-rw-r--r--routes/api/v1/videos.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/routes/api/v1/videos.js b/routes/api/v1/videos.js
index ae70d1640..95c1dffc7 100644
--- a/routes/api/v1/videos.js
+++ b/routes/api/v1/videos.js
@@ -3,6 +3,7 @@
3 3
4 var express = require('express') 4 var express = require('express')
5 var config = require('config') 5 var config = require('config')
6 var crypto = require('crypto')
6 var multer = require('multer') 7 var multer = require('multer')
7 var router = express.Router() 8 var router = express.Router()
8 9
@@ -58,7 +59,24 @@
58 }) 59 })
59 } 60 }
60 61
61 var reqFiles = multer({ dest: uploads }).fields([{ name: 'input_video', maxCount: 1 }]) 62 // multer configuration
63 var storage = multer.diskStorage({
64 destination: function (req, file, cb) {
65 cb(null, uploads)
66 },
67
68 filename: function (req, file, cb) {
69 var extension = ''
70 if (file.mimetype === 'video/webm') extension = 'webm'
71 else if (file.mimetype === 'video/mp4') extension = 'mp4'
72 else if (file.mimetype === 'video/ogg') extension = 'ogv'
73 crypto.pseudoRandomBytes(16, function (err, raw) {
74 var fieldname = err ? undefined : raw.toString('hex')
75 cb(null, fieldname + '.' + extension)
76 })
77 }
78 })
79 var reqFiles = multer({ storage: storage }).fields([{ name: 'input_video', maxCount: 1 }])
62 80
63 router.get('/', miscMiddleware.cache(false), listVideos) 81 router.get('/', miscMiddleware.cache(false), listVideos)
64 router.post('/', reqFiles, reqValidator.videosAdd, miscMiddleware.cache(false), addVideos) 82 router.post('/', reqFiles, reqValidator.videosAdd, miscMiddleware.cache(false), addVideos)