diff options
Diffstat (limited to 'server/controllers/api/v1/videos.js')
-rw-r--r-- | server/controllers/api/v1/videos.js | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js index 76cad62d1..1eea417d4 100644 --- a/server/controllers/api/v1/videos.js +++ b/server/controllers/api/v1/videos.js | |||
@@ -1,41 +1,41 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | var config = require('config') | 3 | const config = require('config') |
4 | var crypto = require('crypto') | 4 | const crypto = require('crypto') |
5 | var express = require('express') | 5 | const express = require('express') |
6 | var multer = require('multer') | 6 | const multer = require('multer') |
7 | 7 | ||
8 | var logger = require('../../../helpers/logger') | 8 | const logger = require('../../../helpers/logger') |
9 | var friends = require('../../../lib/friends') | 9 | const friends = require('../../../lib/friends') |
10 | var middleware = require('../../../middlewares') | 10 | const middleware = require('../../../middlewares') |
11 | var cacheMiddleware = middleware.cache | 11 | const cacheMiddleware = middleware.cache |
12 | var reqValidator = middleware.reqValidators.videos | 12 | const reqValidator = middleware.reqValidators.videos |
13 | var Videos = require('../../../models/videos') // model | 13 | const Videos = require('../../../models/videos') // model |
14 | var videos = require('../../../lib/videos') | 14 | const videos = require('../../../lib/videos') |
15 | var webtorrent = require('../../../lib/webtorrent') | 15 | const webtorrent = require('../../../lib/webtorrent') |
16 | 16 | ||
17 | var router = express.Router() | 17 | const router = express.Router() |
18 | var uploads = config.get('storage.uploads') | 18 | const uploads = config.get('storage.uploads') |
19 | 19 | ||
20 | // multer configuration | 20 | // multer configuration |
21 | var storage = multer.diskStorage({ | 21 | const storage = multer.diskStorage({ |
22 | destination: function (req, file, cb) { | 22 | destination: function (req, file, cb) { |
23 | cb(null, uploads) | 23 | cb(null, uploads) |
24 | }, | 24 | }, |
25 | 25 | ||
26 | filename: function (req, file, cb) { | 26 | filename: function (req, file, cb) { |
27 | var extension = '' | 27 | let extension = '' |
28 | if (file.mimetype === 'video/webm') extension = 'webm' | 28 | if (file.mimetype === 'video/webm') extension = 'webm' |
29 | else if (file.mimetype === 'video/mp4') extension = 'mp4' | 29 | else if (file.mimetype === 'video/mp4') extension = 'mp4' |
30 | else if (file.mimetype === 'video/ogg') extension = 'ogv' | 30 | else if (file.mimetype === 'video/ogg') extension = 'ogv' |
31 | crypto.pseudoRandomBytes(16, function (err, raw) { | 31 | crypto.pseudoRandomBytes(16, function (err, raw) { |
32 | var fieldname = err ? undefined : raw.toString('hex') | 32 | const fieldname = err ? undefined : raw.toString('hex') |
33 | cb(null, fieldname + '.' + extension) | 33 | cb(null, fieldname + '.' + extension) |
34 | }) | 34 | }) |
35 | } | 35 | } |
36 | }) | 36 | }) |
37 | 37 | ||
38 | var reqFiles = multer({ storage: storage }).fields([{ name: 'input_video', maxCount: 1 }]) | 38 | const reqFiles = multer({ storage: storage }).fields([{ name: 'input_video', maxCount: 1 }]) |
39 | 39 | ||
40 | router.get('/', cacheMiddleware.cache(false), listVideos) | 40 | router.get('/', cacheMiddleware.cache(false), listVideos) |
41 | router.post('/', reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo) | 41 | router.post('/', reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo) |
@@ -50,8 +50,8 @@ module.exports = router | |||
50 | // --------------------------------------------------------------------------- | 50 | // --------------------------------------------------------------------------- |
51 | 51 | ||
52 | function addVideo (req, res, next) { | 52 | function addVideo (req, res, next) { |
53 | var video_file = req.files.input_video[0] | 53 | const video_file = req.files.input_video[0] |
54 | var video_infos = req.body | 54 | const video_infos = req.body |
55 | 55 | ||
56 | videos.seed(video_file.path, function (err, torrent) { | 56 | videos.seed(video_file.path, function (err, torrent) { |
57 | if (err) { | 57 | if (err) { |
@@ -59,7 +59,7 @@ function addVideo (req, res, next) { | |||
59 | return next(err) | 59 | return next(err) |
60 | } | 60 | } |
61 | 61 | ||
62 | var video_data = { | 62 | const video_data = { |
63 | name: video_infos.name, | 63 | name: video_infos.name, |
64 | namePath: video_file.filename, | 64 | namePath: video_file.filename, |
65 | description: video_infos.description, | 65 | description: video_infos.description, |
@@ -103,7 +103,7 @@ function listVideos (req, res, next) { | |||
103 | } | 103 | } |
104 | 104 | ||
105 | function removeVideo (req, res, next) { | 105 | function removeVideo (req, res, next) { |
106 | var video_id = req.params.id | 106 | const video_id = req.params.id |
107 | Videos.get(video_id, function (err, video) { | 107 | Videos.get(video_id, function (err, video) { |
108 | if (err) return next(err) | 108 | if (err) return next(err) |
109 | 109 | ||
@@ -111,7 +111,7 @@ function removeVideo (req, res, next) { | |||
111 | Videos.removeOwned(req.params.id, function (err) { | 111 | Videos.removeOwned(req.params.id, function (err) { |
112 | if (err) return next(err) | 112 | if (err) return next(err) |
113 | 113 | ||
114 | var params = { | 114 | const params = { |
115 | name: video.name, | 115 | name: video.name, |
116 | magnetUri: video.magnetUri | 116 | magnetUri: video.magnetUri |
117 | } | 117 | } |