diff options
Diffstat (limited to 'server/controllers/api/v1/videos.js')
-rw-r--r-- | server/controllers/api/v1/videos.js | 30 |
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 @@ | |||
3 | const async = require('async') | 3 | const async = require('async') |
4 | const config = require('config') | 4 | const config = require('config') |
5 | const express = require('express') | 5 | const express = require('express') |
6 | const fs = require('fs') | ||
7 | const path = require('path') | ||
8 | const multer = require('multer') | 6 | const multer = require('multer') |
9 | 7 | ||
10 | const constants = require('../../../initializers/constants') | 8 | const constants = require('../../../initializers/constants') |
@@ -46,7 +44,6 @@ const storage = multer.diskStorage({ | |||
46 | }) | 44 | }) |
47 | 45 | ||
48 | const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) | 46 | const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) |
49 | const thumbnailsDir = path.join(__dirname, '..', '..', '..', '..', config.get('storage.thumbnails')) | ||
50 | 47 | ||
51 | router.get('/', | 48 | router.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) { |