- videos.getVideoDuration(video_file.path, function (err, duration) {
- if (err) {
- // TODO: unseed the video
- logger.error('Cannot retrieve metadata of the file.')
- return next(err)
- }
-
- videos.getVideoThumbnail(video_file.path, function (err, thumbnail_name) {
- if (err) {
- // TODO: unseed the video
- logger.error('Cannot make a thumbnail of the video file.')
- return next(err)
- }
-
- 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,
- thumbnail: thumbnail_name
- }
-
- Videos.add(video_data, function (err) {
- if (err) {
- // TODO unseed the video
- logger.error('Cannot insert this video in the database.')
- return next(err)
- }
-
- fs.readFile(thumbnailsDir + thumbnail_name, 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
- video_data.thumbnail_base64 = new Buffer(data).toString('base64')
- // 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()
- })
- })
- })
- })