From 207fbab44d04ec92d748b6a32ec9a237029f820b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 4 Dec 2015 21:43:26 +0100 Subject: [PATCH] Update node modules --- middlewares/reqValidators/videos.js | 4 ++-- package.json | 14 +++++++------- routes/api/v1/videos.js | 11 +++++++++-- server.js | 4 ---- src/videos.js | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/middlewares/reqValidators/videos.js b/middlewares/reqValidators/videos.js index 3763a657c..8c4e23b6b 100644 --- a/middlewares/reqValidators/videos.js +++ b/middlewares/reqValidators/videos.js @@ -24,8 +24,8 @@ } videos.videosAdd = function (req, res, next) { - req.checkFiles('input_video.originalname', 'Should have an input video').notEmpty() - req.checkFiles('input_video.mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) + req.checkFiles('input_video[0].originalname', 'Should have an input video').notEmpty() + req.checkFiles('input_video[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) req.checkBody('name', 'Should have a name').isLength(1, 50) req.checkBody('description', 'Should have a description').isLength(1, 250) diff --git a/package.json b/package.json index 8f2ed9e74..26161cd76 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,8 @@ "grunt": "^0.4.5", "grunt-browserify": "^4.0.1", "grunt-concurrent": "^2.1.0", - "grunt-contrib-clean": "^0.6.0", - "grunt-contrib-copy": "0.8.0", + "grunt-contrib-clean": "^0.7.0", + "grunt-contrib-copy": "0.8.2", "grunt-contrib-watch": "^0.6.1", "grunt-express-server": "^0.5.1", "grunt-newer": "^1.1.1", @@ -50,17 +50,17 @@ "mkdirp": "^0.5.1", "mongoose": "^4.0.5", "morgan": "^1.5.3", - "multer": "^0.1.8", - "node-ipc": "^3.0.0", + "multer": "^1.1.0", + "node-ipc": "^4.1.0", "openssl-wrapper": "https://github.com/Chocobozzz/node-openssl-wrapper", "request": "^2.57.0", "request-replay": "^0.3.0", - "segfault-handler": "^0.2.4", + "segfault-handler": "^1.0.0", "time-grunt": "^1.2.1", "ursa": "^0.9.1", "validator": "^4.3.0", - "webtorrent": "*", - "winston": "^1.0.1", + "webtorrent": "^0.63.2", + "winston": "^2.1.1", "ws": "^0.8.0" }, "devDependencies": { diff --git a/routes/api/v1/videos.js b/routes/api/v1/videos.js index 33c565437..ae70d1640 100644 --- a/routes/api/v1/videos.js +++ b/routes/api/v1/videos.js @@ -2,12 +2,17 @@ 'use strict' var express = require('express') + var config = require('config') + var multer = require('multer') var router = express.Router() + var middleware = require('../../../middlewares') var miscMiddleware = middleware.misc var reqValidator = middleware.reqValidators.videos var videos = require('../../../src/videos') + var uploads = config.get('storage.uploads') + function listVideos (req, res, next) { videos.list(function (err, videos_list) { if (err) return next(err) @@ -25,7 +30,7 @@ } function addVideos (req, res, next) { - videos.add({ video: req.files.input_video, data: req.body }, function (err) { + videos.add({ video: req.files.input_video[0], data: req.body }, function (err) { if (err) return next(err) // TODO : include Location of the new video @@ -53,8 +58,10 @@ }) } + var reqFiles = multer({ dest: uploads }).fields([{ name: 'input_video', maxCount: 1 }]) + router.get('/', miscMiddleware.cache(false), listVideos) - router.post('/', reqValidator.videosAdd, miscMiddleware.cache(false), addVideos) + router.post('/', reqFiles, reqValidator.videosAdd, miscMiddleware.cache(false), addVideos) router.get('/search/:name', reqValidator.videosSearch, miscMiddleware.cache(false), searchVideos) router.get('/:id', reqValidator.videosGet, miscMiddleware.cache(false), getVideos) router.delete('/:id', reqValidator.videosRemove, miscMiddleware.cache(false), removeVideo) diff --git a/server.js b/server.js index 11402ea78..4b93a7adf 100644 --- a/server.js +++ b/server.js @@ -7,7 +7,6 @@ var expressValidator = require('express-validator') var http = require('http') var morgan = require('morgan') - var multer = require('multer') var path = require('path') var TrackerServer = require('bittorrent-tracker').Server var WebSocketServer = require('ws').Server @@ -44,7 +43,6 @@ // Get configurations var port = config.get('listen.port') - var uploads = config.get('storage.uploads') // ----------- Command line ----------- @@ -54,8 +52,6 @@ app.use(morgan('combined', { stream: logger.stream })) // For body requests app.use(bodyParser.json()) - // For POST file requests - app.use(multer({ dest: uploads })) app.use(bodyParser.urlencoded({ extended: false })) // Validate some params for the API app.use(expressValidator({ diff --git a/src/videos.js b/src/videos.js index e3a5b49f1..32f26abe7 100644 --- a/src/videos.js +++ b/src/videos.js @@ -56,7 +56,7 @@ var params = { name: video_data.name, - namePath: video_file.name, + namePath: video_file.filename, description: video_data.description, magnetUri: torrent.magnetURI, podUrl: http + '://' + host + ':' + port