diff options
Diffstat (limited to 'server/controllers/api/v1/videos.js')
-rw-r--r-- | server/controllers/api/v1/videos.js | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js index c6ea439f9..c86a96a25 100644 --- a/server/controllers/api/v1/videos.js +++ b/server/controllers/api/v1/videos.js | |||
@@ -32,8 +32,8 @@ const storage = multer.diskStorage({ | |||
32 | if (file.mimetype === 'video/webm') extension = 'webm' | 32 | if (file.mimetype === 'video/webm') extension = 'webm' |
33 | else if (file.mimetype === 'video/mp4') extension = 'mp4' | 33 | else if (file.mimetype === 'video/mp4') extension = 'mp4' |
34 | else if (file.mimetype === 'video/ogg') extension = 'ogv' | 34 | else if (file.mimetype === 'video/ogg') extension = 'ogv' |
35 | utils.generateRandomString(16, function (err, random_string) { | 35 | utils.generateRandomString(16, function (err, randomString) { |
36 | const fieldname = err ? undefined : random_string | 36 | const fieldname = err ? undefined : randomString |
37 | cb(null, fieldname + '.' + extension) | 37 | cb(null, fieldname + '.' + extension) |
38 | }) | 38 | }) |
39 | } | 39 | } |
@@ -55,47 +55,47 @@ module.exports = router | |||
55 | // --------------------------------------------------------------------------- | 55 | // --------------------------------------------------------------------------- |
56 | 56 | ||
57 | function addVideo (req, res, next) { | 57 | function addVideo (req, res, next) { |
58 | const video_file = req.files.videofile[0] | 58 | const videoFile = req.files.videofile[0] |
59 | const video_infos = req.body | 59 | const videoInfos = req.body |
60 | 60 | ||
61 | videos.seed(video_file.path, function (err, torrent) { | 61 | videos.seed(videoFile.path, function (err, torrent) { |
62 | if (err) { | 62 | if (err) { |
63 | logger.error('Cannot seed this video.') | 63 | logger.error('Cannot seed this video.') |
64 | return next(err) | 64 | return next(err) |
65 | } | 65 | } |
66 | 66 | ||
67 | videos.getVideoDuration(video_file.path, function (err, duration) { | 67 | videos.getVideoDuration(videoFile.path, function (err, duration) { |
68 | if (err) { | 68 | if (err) { |
69 | // TODO: unseed the video | 69 | // TODO: unseed the video |
70 | logger.error('Cannot retrieve metadata of the file.') | 70 | logger.error('Cannot retrieve metadata of the file.') |
71 | return next(err) | 71 | return next(err) |
72 | } | 72 | } |
73 | 73 | ||
74 | videos.getVideoThumbnail(video_file.path, function (err, thumbnail_name) { | 74 | videos.getVideoThumbnail(videoFile.path, function (err, thumbnailName) { |
75 | if (err) { | 75 | if (err) { |
76 | // TODO: unseed the video | 76 | // TODO: unseed the video |
77 | logger.error('Cannot make a thumbnail of the video file.') | 77 | logger.error('Cannot make a thumbnail of the video file.') |
78 | return next(err) | 78 | return next(err) |
79 | } | 79 | } |
80 | 80 | ||
81 | const video_data = { | 81 | const videoData = { |
82 | name: video_infos.name, | 82 | name: videoInfos.name, |
83 | namePath: video_file.filename, | 83 | namePath: videoFile.filename, |
84 | description: video_infos.description, | 84 | description: videoInfos.description, |
85 | magnetUri: torrent.magnetURI, | 85 | magnetUri: torrent.magnetURI, |
86 | author: res.locals.oauth.token.user.username, | 86 | author: res.locals.oauth.token.user.username, |
87 | duration: duration, | 87 | duration: duration, |
88 | thumbnail: thumbnail_name | 88 | thumbnail: thumbnailName |
89 | } | 89 | } |
90 | 90 | ||
91 | Videos.add(video_data, function (err) { | 91 | Videos.add(videoData, function (err) { |
92 | if (err) { | 92 | if (err) { |
93 | // TODO unseed the video | 93 | // TODO unseed the video |
94 | logger.error('Cannot insert this video in the database.') | 94 | logger.error('Cannot insert this video in the database.') |
95 | return next(err) | 95 | return next(err) |
96 | } | 96 | } |
97 | 97 | ||
98 | fs.readFile(thumbnailsDir + thumbnail_name, function (err, data) { | 98 | fs.readFile(thumbnailsDir + thumbnailName, function (err, data) { |
99 | if (err) { | 99 | if (err) { |
100 | // TODO: remove video? | 100 | // TODO: remove video? |
101 | logger.error('Cannot read the thumbnail of the video') | 101 | logger.error('Cannot read the thumbnail of the video') |
@@ -103,9 +103,9 @@ function addVideo (req, res, next) { | |||
103 | } | 103 | } |
104 | 104 | ||
105 | // Set the image in base64 | 105 | // Set the image in base64 |
106 | video_data.thumbnail_base64 = new Buffer(data).toString('base64') | 106 | videoData.thumbnailBase64 = new Buffer(data).toString('base64') |
107 | // Now we'll add the video's meta data to our friends | 107 | // Now we'll add the video's meta data to our friends |
108 | friends.addVideoToFriends(video_data) | 108 | friends.addVideoToFriends(videoData) |
109 | 109 | ||
110 | // TODO : include Location of the new video -> 201 | 110 | // TODO : include Location of the new video -> 201 |
111 | res.type('json').status(204).end() | 111 | res.type('json').status(204).end() |
@@ -117,29 +117,29 @@ function addVideo (req, res, next) { | |||
117 | } | 117 | } |
118 | 118 | ||
119 | function getVideos (req, res, next) { | 119 | function getVideos (req, res, next) { |
120 | Videos.get(req.params.id, function (err, video_obj) { | 120 | Videos.get(req.params.id, function (err, videoObj) { |
121 | if (err) return next(err) | 121 | if (err) return next(err) |
122 | 122 | ||
123 | const state = videos.getVideoState(video_obj) | 123 | const state = videos.getVideoState(videoObj) |
124 | if (state.exist === false) { | 124 | if (state.exist === false) { |
125 | return res.type('json').status(204).end() | 125 | return res.type('json').status(204).end() |
126 | } | 126 | } |
127 | 127 | ||
128 | res.json(getFormatedVideo(video_obj)) | 128 | res.json(getFormatedVideo(videoObj)) |
129 | }) | 129 | }) |
130 | } | 130 | } |
131 | 131 | ||
132 | function listVideos (req, res, next) { | 132 | function listVideos (req, res, next) { |
133 | Videos.list(function (err, videos_list) { | 133 | Videos.list(function (err, videosList) { |
134 | if (err) return next(err) | 134 | if (err) return next(err) |
135 | 135 | ||
136 | res.json(getFormatedVideos(videos_list)) | 136 | res.json(getFormatedVideos(videosList)) |
137 | }) | 137 | }) |
138 | } | 138 | } |
139 | 139 | ||
140 | function removeVideo (req, res, next) { | 140 | function removeVideo (req, res, next) { |
141 | const video_id = req.params.id | 141 | const videoId = req.params.id |
142 | Videos.get(video_id, function (err, video) { | 142 | Videos.get(videoId, function (err, video) { |
143 | if (err) return next(err) | 143 | if (err) return next(err) |
144 | 144 | ||
145 | removeTorrent(video.magnetUri, function () { | 145 | removeTorrent(video.magnetUri, function () { |
@@ -163,39 +163,39 @@ function removeVideo (req, res, next) { | |||
163 | } | 163 | } |
164 | 164 | ||
165 | function searchVideos (req, res, next) { | 165 | function searchVideos (req, res, next) { |
166 | Videos.search(req.params.name, function (err, videos_list) { | 166 | Videos.search(req.params.name, function (err, videosList) { |
167 | if (err) return next(err) | 167 | if (err) return next(err) |
168 | 168 | ||
169 | res.json(getFormatedVideos(videos_list)) | 169 | res.json(getFormatedVideos(videosList)) |
170 | }) | 170 | }) |
171 | } | 171 | } |
172 | 172 | ||
173 | // --------------------------------------------------------------------------- | 173 | // --------------------------------------------------------------------------- |
174 | 174 | ||
175 | function getFormatedVideo (video_obj) { | 175 | function getFormatedVideo (videoObj) { |
176 | const formated_video = { | 176 | const formatedVideo = { |
177 | id: video_obj._id, | 177 | id: videoObj._id, |
178 | name: video_obj.name, | 178 | name: videoObj.name, |
179 | description: video_obj.description, | 179 | description: videoObj.description, |
180 | podUrl: video_obj.podUrl, | 180 | podUrl: videoObj.podUrl, |
181 | isLocal: videos.getVideoState(video_obj).owned, | 181 | isLocal: videos.getVideoState(videoObj).owned, |
182 | magnetUri: video_obj.magnetUri, | 182 | magnetUri: videoObj.magnetUri, |
183 | author: video_obj.author, | 183 | author: videoObj.author, |
184 | duration: video_obj.duration, | 184 | duration: videoObj.duration, |
185 | thumbnailPath: constants.THUMBNAILS_STATIC_PATH + '/' + video_obj.thumbnail | 185 | thumbnailPath: constants.THUMBNAILS_STATIC_PATH + '/' + videoObj.thumbnail |
186 | } | 186 | } |
187 | 187 | ||
188 | return formated_video | 188 | return formatedVideo |
189 | } | 189 | } |
190 | 190 | ||
191 | function getFormatedVideos (videos_obj) { | 191 | function getFormatedVideos (videosObj) { |
192 | const formated_videos = [] | 192 | const formatedVideos = [] |
193 | 193 | ||
194 | videos_obj.forEach(function (video_obj) { | 194 | videosObj.forEach(function (videoObj) { |
195 | formated_videos.push(getFormatedVideo(video_obj)) | 195 | formatedVideos.push(getFormatedVideo(videoObj)) |
196 | }) | 196 | }) |
197 | 197 | ||
198 | return formated_videos | 198 | return formatedVideos |
199 | } | 199 | } |
200 | 200 | ||
201 | // Maybe the torrent is not seeded, but we catch the error to don't stop the removing process | 201 | // Maybe the torrent is not seeded, but we catch the error to don't stop the removing process |