const videoInfos = req.body
async.waterfall([
- function (callback) {
+ function seedTheVideo (callback) {
videos.seed(videoFile.path, callback)
},
- function seed (torrent, callback) {
- videos.getVideoDuration(videoFile.path, function (err, duration) {
- if (err) {
- // TODO: unseed the video
- logger.error('Cannot retrieve metadata of the file.')
- return next(err)
- }
-
- callback(null, torrent, duration)
- })
- },
-
- function createThumbnail (torrent, duration, callback) {
+ function createThumbnail (torrent, callback) {
videos.createVideoThumbnail(videoFile.path, function (err, thumbnailName) {
if (err) {
// TODO: unseed the video
return callback(err)
}
- callback(null, torrent, duration, thumbnailName)
+ callback(null, torrent, thumbnailName)
})
},
- function insertIntoDB (torrent, duration, thumbnailName, callback) {
+ function insertIntoDB (torrent, thumbnailName, callback) {
const videoData = {
name: videoInfos.name,
namePath: videoFile.filename,
description: videoInfos.description,
magnetUri: torrent.magnetURI,
author: res.locals.oauth.token.user.username,
- duration: duration,
+ duration: videoFile.duration,
thumbnail: thumbnailName
}
return callback(err)
}
- return callback(null, torrent, duration, thumbnailName, videoData, insertedVideo)
+ return callback(null, torrent, thumbnailName, videoData, insertedVideo)
})
},
- function getThumbnailBase64 (torrent, duration, thumbnailName, videoData, insertedVideo, callback) {
+ function getThumbnailBase64 (torrent, thumbnailName, videoData, insertedVideo, callback) {
videoData.createdDate = insertedVideo.createdDate
fs.readFile(thumbnailsDir + thumbnailName, function (err, thumbnailData) {
const validator = require('validator')
+const constants = require('../initializers/constants')
+
const customValidators = {
eachIsRemoteVideosAddValid: eachIsRemoteVideosAddValid,
eachIsRemoteVideosRemoveValid: eachIsRemoteVideosRemoveValid,
validator.isLength(val.magnetUri, 10) &&
validator.isURL(val.podUrl) &&
!isNaN(val.duration) &&
+ val.duration >= 0 &&
+ val.duration < constants.MAXIMUM_VIDEO_DURATION &&
validator.isDate(val.createdDate)
})
}
// Time to wait between requests to the friends
let INTERVAL = 60000
+// 2 hours maximum for the duration of a video (in seconds)
+let MAXIMUM_VIDEO_DURATION = 7200
+
// Number of results by default for the pagination
const PAGINATION_COUNT_DEFAULT = 15
if (isTestInstance() === true) {
FRIEND_BASE_SCORE = 20
INTERVAL = 10000
+ MAXIMUM_VIDEO_DURATION = 14
REQUEST_RETRIES = 2
}
API_VERSION: API_VERSION,
FRIEND_BASE_SCORE: FRIEND_BASE_SCORE,
INTERVAL: INTERVAL,
+ MAXIMUM_VIDEO_DURATION: MAXIMUM_VIDEO_DURATION,
PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT,
PODS_SCORE: PODS_SCORE,
REQUEST_RETRIES: REQUEST_RETRIES,
'use strict'
const checkErrors = require('./utils').checkErrors
+const constants = require('../../initializers/constants')
const logger = require('../../helpers/logger')
const videos = require('../../lib/videos')
const Videos = require('../../models/videos')
logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
- checkErrors(req, res, next)
+ checkErrors(req, res, function () {
+ const videoFile = req.files.videofile[0]
+
+ videos.getVideoDuration(videoFile.path, function (err, duration) {
+ if (err) {
+ return res.status(400).send('Cannot retrieve metadata of the file.')
+ }
+
+ if (duration > constants.MAXIMUM_VIDEO_DURATION) {
+ return res.status(400).send('Duration of the video file is too big.')
+ }
+
+ videoFile.duration = duration
+ next()
+ })
+ })
}
function videosGet (req, res, next) {
describe('Test parameters validator', function () {
let server = null
- function makePostRequest (path, token, fields, attach, done, fail) {
+ function makePostRequest (path, token, fields, attaches, done, fail) {
let statusCode = 400
- if (fail !== undefined && fail === false) statusCode = 200
+ if (fail !== undefined && fail === false) statusCode = 204
const req = request(server.url)
.post(path)
req.field(field, value)
})
+ Object.keys(attaches).forEach(function (attach) {
+ const value = attaches[attach]
+ req.attach(attach, value)
+ })
+
req.expect(statusCode, done)
}
description: 'my super description'
}
const attach = {
- 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
+ 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm')
+ }
+ makePostRequest(path, server.accessToken, data, attach, done)
+ })
+
+ it('Should fail with a too big duration', function (done) {
+ const data = {
+ name: 'my super name',
+ description: 'my super description'
+ }
+ const attach = {
+ 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm')
}
makePostRequest(path, server.accessToken, data, attach, done)
})
attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4')
makePostRequest(path, server.accessToken, data, attach, function () {
attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv')
- makePostRequest(path, server.accessToken, data, attach, done, true)
- }, true)
- }, true)
+ makePostRequest(path, server.accessToken, data, attach, done, false)
+ }, false)
+ }, false)
})
})
if (err) throw err
expect(res.body).to.be.an('array')
- expect(res.body.length).to.equal(0)
+ expect(res.body.length).to.equal(3)
done()
})