aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/v1/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/v1/videos.js')
-rw-r--r--server/controllers/api/v1/videos.js30
1 files changed, 9 insertions, 21 deletions
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js
index 5449cbcfa..2edb31122 100644
--- a/server/controllers/api/v1/videos.js
+++ b/server/controllers/api/v1/videos.js
@@ -3,8 +3,6 @@
3const async = require('async') 3const async = require('async')
4const config = require('config') 4const config = require('config')
5const express = require('express') 5const express = require('express')
6const fs = require('fs')
7const path = require('path')
8const multer = require('multer') 6const multer = require('multer')
9 7
10const constants = require('../../../initializers/constants') 8const constants = require('../../../initializers/constants')
@@ -46,7 +44,6 @@ const storage = multer.diskStorage({
46}) 44})
47 45
48const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) 46const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }])
49const thumbnailsDir = path.join(__dirname, '..', '..', '..', '..', config.get('storage.thumbnails'))
50 47
51router.get('/', 48router.get('/',
52 reqValidatorPagination.pagination, 49 reqValidatorPagination.pagination,
@@ -127,34 +124,25 @@ function addVideo (req, res, next) {
127 return callback(err) 124 return callback(err)
128 } 125 }
129 126
130 return callback(null, torrent, thumbnailName, videoData, insertedVideo) 127 return callback(null, insertedVideo)
131 }) 128 })
132 }, 129 },
133 130
134 function getThumbnailBase64 (torrent, thumbnailName, videoData, insertedVideo, callback) { 131 function sendToFriends (insertedVideo, callback) {
135 videoData.createdDate = insertedVideo.createdDate 132 videos.convertVideoToRemote(insertedVideo, function (err, remoteVideo) {
136
137 fs.readFile(thumbnailsDir + thumbnailName, function (err, thumbnailData) {
138 if (err) { 133 if (err) {
139 // TODO unseed the video 134 // TODO unseed the video
140 // TODO remove thumbnail 135 // TODO remove thumbnail
141 // TODO: remove video 136 // TODO delete from DB
142 logger.error('Cannot read the thumbnail of the video') 137 logger.error('Cannot convert video to remote.')
143 return callback(err) 138 return callback(err)
144 } 139 }
145 140
146 return callback(null, videoData, thumbnailData) 141 // Now we'll add the video's meta data to our friends
147 }) 142 friends.addVideoToFriends(remoteVideo)
148 },
149
150 function sendToFriends (videoData, thumbnailData, callback) {
151 // Set the image in base64
152 videoData.thumbnailBase64 = new Buffer(thumbnailData).toString('base64')
153 143
154 // Now we'll add the video's meta data to our friends 144 return callback(null)
155 friends.addVideoToFriends(videoData) 145 })
156
157 return callback(null)
158 } 146 }
159 147
160 ], function andFinally (err) { 148 ], function andFinally (err) {