const logger = require('../../../helpers/logger')
const friends = require('../../../lib/friends')
const middleware = require('../../../middlewares')
+const oAuth2 = require('../../../middlewares/oauth2')
const cacheMiddleware = middleware.cache
const reqValidator = middleware.reqValidators.videos
const Videos = require('../../../models/videos') // model
const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }])
router.get('/', cacheMiddleware.cache(false), listVideos)
-router.post('/', reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo)
+router.post('/', oAuth2.authenticate, reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo)
router.get('/:id', reqValidator.videosGet, cacheMiddleware.cache(false), getVideos)
-router.delete('/:id', reqValidator.videosRemove, cacheMiddleware.cache(false), removeVideo)
+router.delete('/:id', oAuth2.authenticate, reqValidator.videosRemove, cacheMiddleware.cache(false), removeVideo)
router.get('/search/:name', reqValidator.videosSearch, cacheMiddleware.cache(false), searchVideos)
// ---------------------------------------------------------------------------
return next(err)
}
- const video_data = {
- name: video_infos.name,
- namePath: video_file.filename,
- description: video_infos.description,
- magnetUri: torrent.magnetURI
- }
-
- Videos.add(video_data, function (err) {
+ videos.getVideoDuration(video_file.path, function (err, duration) {
if (err) {
- // TODO unseed the video
- logger.error('Cannot insert this video in the database.')
+ // TODO: unseed the video
+ logger.error('Cannot retrieve metadata of the file')
return next(err)
}
- // Now we'll add the video's meta data to our friends
- friends.addVideoToFriends(video_data)
+ const video_data = {
+ name: video_infos.name,
+ namePath: video_file.filename,
+ description: video_infos.description,
+ magnetUri: torrent.magnetURI,
+ author: res.locals.oauth.token.user.username,
+ duration: duration
+ }
+
+ Videos.add(video_data, function (err) {
+ if (err) {
+ // TODO unseed the video
+ logger.error('Cannot insert this video in the database.')
+ return next(err)
+ }
+
+ // Now we'll add the video's meta data to our friends
+ friends.addVideoToFriends(video_data)
- // TODO : include Location of the new video -> 201
- res.type('json').status(204).end()
+ // TODO : include Location of the new video -> 201
+ res.type('json').status(204).end()
+ })
})
})
}
description: video_obj.description,
podUrl: video_obj.podUrl,
isLocal: videos.getVideoState(video_obj).owned,
- magnetUri: video_obj.magnetUri
+ magnetUri: video_obj.magnetUri,
+ author: video_obj.author,
+ duration: video_obj.duration
}
return formated_video