+ Videos.add(videoData, function (err, insertedVideo) {
+ if (err) {
+ // TODO unseed the video
+ // TODO remove thumbnail
+ logger.error('Cannot insert this video in the database.')
+ return callback(err)
+ }
+
+ return callback(null, torrent, thumbnailName, videoData, insertedVideo)
+ })
+ },
+
+ function getThumbnailBase64 (torrent, thumbnailName, videoData, insertedVideo, callback) {
+ videoData.createdDate = insertedVideo.createdDate
+
+ fs.readFile(thumbnailsDir + thumbnailName, function (err, thumbnailData) {
+ if (err) {
+ // TODO unseed the video
+ // TODO remove thumbnail
+ // TODO: remove video
+ logger.error('Cannot read the thumbnail of the video')
+ return callback(err)
+ }
+
+ return callback(null, videoData, thumbnailData)
+ })
+ },
+
+ function sendToFriends (videoData, thumbnailData, callback) {
+ // Set the image in base64
+ videoData.thumbnailBase64 = new Buffer(thumbnailData).toString('base64')
+