diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-17 21:42:47 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-17 21:42:47 +0100 |
commit | 15103f11ec54989a0dee7fc33daa458ecb116fe4 (patch) | |
tree | b25f8ee33f32ccd61df46afc27a2a4628f9f0be5 /server/models | |
parent | 1e4b0080ff1b4e802f71ec1f4cbf8cbcc70cdcbd (diff) | |
download | PeerTube-15103f11ec54989a0dee7fc33daa458ecb116fe4.tar.gz PeerTube-15103f11ec54989a0dee7fc33daa458ecb116fe4.tar.zst PeerTube-15103f11ec54989a0dee7fc33daa458ecb116fe4.zip |
Server: paths refractoring
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video.js | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/server/models/video.js b/server/models/video.js index 17eff6428..742150d69 100644 --- a/server/models/video.js +++ b/server/models/video.js | |||
@@ -157,8 +157,7 @@ function beforeCreate (video, options, next) { | |||
157 | const videoPath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename()) | 157 | const videoPath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename()) |
158 | 158 | ||
159 | tasks.push( | 159 | tasks.push( |
160 | // TODO: refractoring | 160 | function createVideoTorrent (callback) { |
161 | function (callback) { | ||
162 | const options = { | 161 | const options = { |
163 | announceList: [ | 162 | announceList: [ |
164 | [ constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT + '/tracker/socket' ] | 163 | [ constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT + '/tracker/socket' ] |
@@ -171,7 +170,8 @@ function beforeCreate (video, options, next) { | |||
171 | createTorrent(videoPath, options, function (err, torrent) { | 170 | createTorrent(videoPath, options, function (err, torrent) { |
172 | if (err) return callback(err) | 171 | if (err) return callback(err) |
173 | 172 | ||
174 | fs.writeFile(constants.CONFIG.STORAGE.TORRENTS_DIR + video.getTorrentName(), torrent, function (err) { | 173 | const filePath = pathUtils.join(constants.CONFIG.STORAGE.TORRENTS_DIR, video.getTorrentName()) |
174 | fs.writeFile(filePath, torrent, function (err) { | ||
175 | if (err) return callback(err) | 175 | if (err) return callback(err) |
176 | 176 | ||
177 | const parsedTorrent = parseTorrent(torrent) | 177 | const parsedTorrent = parseTorrent(torrent) |
@@ -180,10 +180,12 @@ function beforeCreate (video, options, next) { | |||
180 | }) | 180 | }) |
181 | }) | 181 | }) |
182 | }, | 182 | }, |
183 | function (callback) { | 183 | |
184 | function createVideoThumbnail (callback) { | ||
184 | createThumbnail(video, videoPath, callback) | 185 | createThumbnail(video, videoPath, callback) |
185 | }, | 186 | }, |
186 | function (callback) { | 187 | |
188 | function createVIdeoPreview (callback) { | ||
187 | createPreview(video, videoPath, callback) | 189 | createPreview(video, videoPath, callback) |
188 | } | 190 | } |
189 | ) | 191 | ) |
@@ -205,19 +207,19 @@ function afterDestroy (video, options, next) { | |||
205 | 207 | ||
206 | if (video.isOwned()) { | 208 | if (video.isOwned()) { |
207 | tasks.push( | 209 | tasks.push( |
208 | function (callback) { | 210 | function removeVideoFile (callback) { |
209 | removeFile(video, callback) | 211 | removeFile(video, callback) |
210 | }, | 212 | }, |
211 | 213 | ||
212 | function (callback) { | 214 | function removeVideoTorrent (callback) { |
213 | removeTorrent(video, callback) | 215 | removeTorrent(video, callback) |
214 | }, | 216 | }, |
215 | 217 | ||
216 | function (callback) { | 218 | function removeVideoPreview (callback) { |
217 | removePreview(video, callback) | 219 | removePreview(video, callback) |
218 | }, | 220 | }, |
219 | 221 | ||
220 | function (callback) { | 222 | function removeVideoToFriends (callback) { |
221 | const params = { | 223 | const params = { |
222 | remoteId: video.id | 224 | remoteId: video.id |
223 | } | 225 | } |
@@ -395,7 +397,7 @@ function generateThumbnailFromData (video, thumbnailData, callback) { | |||
395 | // Creating the thumbnail for a remote video | 397 | // Creating the thumbnail for a remote video |
396 | 398 | ||
397 | const thumbnailName = video.getThumbnailName() | 399 | const thumbnailName = video.getThumbnailName() |
398 | const thumbnailPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName | 400 | const thumbnailPath = pathUtils.join(constants.CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName) |
399 | fs.writeFile(thumbnailPath, Buffer.from(thumbnailData, 'binary'), function (err) { | 401 | fs.writeFile(thumbnailPath, Buffer.from(thumbnailData, 'binary'), function (err) { |
400 | if (err) return callback(err) | 402 | if (err) return callback(err) |
401 | 403 | ||
@@ -596,15 +598,18 @@ function searchAndPopulateAuthorAndPodAndTags (value, field, start, count, sort, | |||
596 | // --------------------------------------------------------------------------- | 598 | // --------------------------------------------------------------------------- |
597 | 599 | ||
598 | function removeThumbnail (video, callback) { | 600 | function removeThumbnail (video, callback) { |
599 | fs.unlink(constants.CONFIG.STORAGE.THUMBNAILS_DIR + video.getThumbnailName(), callback) | 601 | const thumbnailPath = pathUtils.join(constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName()) |
602 | fs.unlink(thumbnailPath, callback) | ||
600 | } | 603 | } |
601 | 604 | ||
602 | function removeFile (video, callback) { | 605 | function removeFile (video, callback) { |
603 | fs.unlink(constants.CONFIG.STORAGE.VIDEOS_DIR + video.getVideoFilename(), callback) | 606 | const filePath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename()) |
607 | fs.unlink(filePath, callback) | ||
604 | } | 608 | } |
605 | 609 | ||
606 | function removeTorrent (video, callback) { | 610 | function removeTorrent (video, callback) { |
607 | fs.unlink(constants.CONFIG.STORAGE.TORRENTS_DIR + video.getTorrentName(), callback) | 611 | const torrenPath = pathUtils.join(constants.CONFIG.STORAGE.TORRENTS_DIR, video.getTorrentName()) |
612 | fs.unlink(torrenPath, callback) | ||
608 | } | 613 | } |
609 | 614 | ||
610 | function removePreview (video, callback) { | 615 | function removePreview (video, callback) { |