- videos.getVideoThumbnail(videoFile.path, function (err, thumbnailName) {
- if (err) {
- // TODO: unseed the video
- logger.error('Cannot make a thumbnail of the video file.')
- return next(err)
- }
-
- const videoData = {
- name: videoInfos.name,
- namePath: videoFile.filename,
- description: videoInfos.description,
- magnetUri: torrent.magnetURI,
- author: res.locals.oauth.token.user.username,
- duration: duration,
- thumbnail: thumbnailName
- }
-
- Videos.add(videoData, function (err) {
- if (err) {
- // TODO unseed the video
- logger.error('Cannot insert this video in the database.')
- return next(err)
- }
-
- fs.readFile(thumbnailsDir + thumbnailName, function (err, data) {
- if (err) {
- // TODO: remove video?
- logger.error('Cannot read the thumbnail of the video')
- return next(err)
- }
-
- // Set the image in base64
- videoData.thumbnailBase64 = new Buffer(data).toString('base64')
- // Now we'll add the video's meta data to our friends
- friends.addVideoToFriends(videoData)
-
- // TODO : include Location of the new video -> 201
- res.type('json').status(204).end()
- })
- })
+ const video = new Video(videoData)
+ video.save(function (err, video) {
+ // Assert there are only one argument sent to the next function (video)
+ return callback(err, video)