diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video.js | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/server/models/video.js b/server/models/video.js index 63afc2efe..0f60b6cd4 100644 --- a/server/models/video.js +++ b/server/models/video.js | |||
@@ -1,6 +1,5 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const config = require('config') | ||
4 | const eachLimit = require('async/eachLimit') | 3 | const eachLimit = require('async/eachLimit') |
5 | const ffmpeg = require('fluent-ffmpeg') | 4 | const ffmpeg = require('fluent-ffmpeg') |
6 | const fs = require('fs') | 5 | const fs = require('fs') |
@@ -15,12 +14,6 @@ const modelUtils = require('./utils') | |||
15 | const utils = require('../helpers/utils') | 14 | const utils = require('../helpers/utils') |
16 | const webtorrent = require('../lib/webtorrent') | 15 | const webtorrent = require('../lib/webtorrent') |
17 | 16 | ||
18 | const http = config.get('webserver.https') === true ? 'https' : 'http' | ||
19 | const host = config.get('webserver.host') | ||
20 | const port = config.get('webserver.port') | ||
21 | const uploadsDir = pathUtils.join(__dirname, '..', '..', config.get('storage.uploads')) | ||
22 | const thumbnailsDir = pathUtils.join(__dirname, '..', '..', config.get('storage.thumbnails')) | ||
23 | |||
24 | // --------------------------------------------------------------------------- | 17 | // --------------------------------------------------------------------------- |
25 | 18 | ||
26 | // TODO: add indexes on searchable columns | 19 | // TODO: add indexes on searchable columns |
@@ -101,8 +94,8 @@ VideoSchema.pre('save', function (next) { | |||
101 | const tasks = [] | 94 | const tasks = [] |
102 | 95 | ||
103 | if (video.isOwned()) { | 96 | if (video.isOwned()) { |
104 | const videoPath = pathUtils.join(uploadsDir, video.filename) | 97 | const videoPath = pathUtils.join(constants.CONFIG.STORAGE.UPLOAD_DIR, video.filename) |
105 | this.podUrl = http + '://' + host + ':' + port | 98 | this.podUrl = constants.CONFIG.WEBSERVER.URL |
106 | 99 | ||
107 | tasks.push( | 100 | tasks.push( |
108 | function (callback) { | 101 | function (callback) { |
@@ -162,7 +155,7 @@ function toRemoteJSON (callback) { | |||
162 | const self = this | 155 | const self = this |
163 | 156 | ||
164 | // Convert thumbnail to base64 | 157 | // Convert thumbnail to base64 |
165 | fs.readFile(pathUtils.join(thumbnailsDir, this.thumbnail), function (err, thumbnailData) { | 158 | fs.readFile(pathUtils.join(constants.CONFIG.STORAGE.THUMBNAILS_DIR, this.thumbnail), function (err, thumbnailData) { |
166 | if (err) { | 159 | if (err) { |
167 | logger.error('Cannot read the thumbnail of the video') | 160 | logger.error('Cannot read the thumbnail of the video') |
168 | return callback(err) | 161 | return callback(err) |
@@ -242,7 +235,7 @@ function seedAllExisting (callback) { | |||
242 | if (err) return callback(err) | 235 | if (err) return callback(err) |
243 | 236 | ||
244 | eachLimit(videos, constants.SEEDS_IN_PARALLEL, function (video, callbackEach) { | 237 | eachLimit(videos, constants.SEEDS_IN_PARALLEL, function (video, callbackEach) { |
245 | const videoPath = pathUtils.join(uploadsDir, video.filename) | 238 | const videoPath = pathUtils.join(constants.CONFIG.STORAGE.UPLOAD_DIR, video.filename) |
246 | seed(videoPath, callbackEach) | 239 | seed(videoPath, callbackEach) |
247 | }, callback) | 240 | }, callback) |
248 | }) | 241 | }) |
@@ -251,11 +244,11 @@ function seedAllExisting (callback) { | |||
251 | // --------------------------------------------------------------------------- | 244 | // --------------------------------------------------------------------------- |
252 | 245 | ||
253 | function removeThumbnail (video, callback) { | 246 | function removeThumbnail (video, callback) { |
254 | fs.unlink(thumbnailsDir + video.thumbnail, callback) | 247 | fs.unlink(constants.CONFIG.STORAGE.THUMBNAILS_DIR + video.thumbnail, callback) |
255 | } | 248 | } |
256 | 249 | ||
257 | function removeFile (video, callback) { | 250 | function removeFile (video, callback) { |
258 | fs.unlink(uploadsDir + video.filename, callback) | 251 | fs.unlink(constants.CONFIG.STORAGE.UPLOAD_DIR + video.filename, callback) |
259 | } | 252 | } |
260 | 253 | ||
261 | // Maybe the torrent is not seeded, but we catch the error to don't stop the removing process | 254 | // Maybe the torrent is not seeded, but we catch the error to don't stop the removing process |
@@ -277,7 +270,7 @@ function createThumbnail (videoPath, callback) { | |||
277 | }) | 270 | }) |
278 | .thumbnail({ | 271 | .thumbnail({ |
279 | count: 1, | 272 | count: 1, |
280 | folder: thumbnailsDir, | 273 | folder: constants.CONFIG.STORAGE.THUMBNAILS_DIR, |
281 | size: constants.THUMBNAILS_SIZE, | 274 | size: constants.THUMBNAILS_SIZE, |
282 | filename: filename | 275 | filename: filename |
283 | }) | 276 | }) |
@@ -299,7 +292,7 @@ function generateThumbnailFromBase64 (data, callback) { | |||
299 | if (err) return callback(err) | 292 | if (err) return callback(err) |
300 | 293 | ||
301 | const thumbnailName = randomString + '.jpg' | 294 | const thumbnailName = randomString + '.jpg' |
302 | fs.writeFile(thumbnailsDir + thumbnailName, data, { encoding: 'base64' }, function (err) { | 295 | fs.writeFile(constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName, data, { encoding: 'base64' }, function (err) { |
303 | if (err) return callback(err) | 296 | if (err) return callback(err) |
304 | 297 | ||
305 | return callback(null, thumbnailName) | 298 | return callback(null, thumbnailName) |