aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-01-09 12:59:13 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-01-09 12:59:13 +0100
commite78a20c7f914423736f7b5b0bf981418e43b6c36 (patch)
treed0c12867a7fad48bd29ebe89f709036e94f18a29
parent4884d60337c141197070eefa7e19ae2b0043ae6b (diff)
downloadPeerTube-e78a20c7f914423736f7b5b0bf981418e43b6c36.tar.gz
PeerTube-e78a20c7f914423736f7b5b0bf981418e43b6c36.tar.zst
PeerTube-e78a20c7f914423736f7b5b0bf981418e43b6c36.zip
Fix upload of file which don't have any extension
-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)