X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo.js;h=05c4f51cb2d7211918e71f5c261b605c2d90b51c;hb=2c49ca42d14087ce8e1695759435f796a290470b;hp=7d073cffa97cb33b43b03246909f7a6fe4e58b53;hpb=aff36eb063573532498979c83be1c279c84f2d53;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video.js b/server/models/video.js index 7d073cffa..05c4f51cb 100644 --- a/server/models/video.js +++ b/server/models/video.js @@ -1,6 +1,5 @@ 'use strict' -const config = require('config') const createTorrent = require('create-torrent') const ffmpeg = require('fluent-ffmpeg') const fs = require('fs') @@ -16,14 +15,6 @@ const logger = require('../helpers/logger') const modelUtils = require('./utils') const utils = require('../helpers/utils') -const http = config.get('webserver.https') === true ? 'https' : 'http' -const host = config.get('webserver.host') -const port = config.get('webserver.port') -const uploadsDir = pathUtils.join(__dirname, '..', '..', config.get('storage.uploads')) -const thumbnailsDir = pathUtils.join(__dirname, '..', '..', config.get('storage.thumbnails')) -const torrentsDir = pathUtils.join(__dirname, '..', '..', config.get('storage.torrents')) -const webseedBaseUrl = http + '://' + host + ':' + port + constants.STATIC_PATHS.WEBSEED - // --------------------------------------------------------------------------- // TODO: add indexes on searchable columns @@ -66,7 +57,7 @@ VideoSchema.statics = { getDurationFromFile, listForApi, listByUrlAndMagnet, - listByUrls, + listByUrl, listOwned, listOwnedByAuthor, listRemotes, @@ -103,16 +94,25 @@ VideoSchema.pre('save', function (next) { const tasks = [] if (video.isOwned()) { - const videoPath = pathUtils.join(constants.CONFIG.STORAGE.UPLOAD_DIR, video.filename) + const videoPath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.filename) this.podUrl = constants.CONFIG.WEBSERVER.URL tasks.push( // TODO: refractoring function (callback) { - createTorrent(videoPath, { announceList: [ [ 'ws://' + host + ':' + port + '/tracker/socket' ] ], urlList: [ webseedBaseUrl + video.filename ] }, function (err, torrent) { + const options = { + announceList: [ + [ constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOST + ':' + constants.CONFIG.WEBSERVER.PORT + '/tracker/socket' ] + ], + urlList: [ + constants.CONFIG.WEBSERVER.URL + constants.STATIC_PATHS.WEBSEED + video.filename + ] + } + + createTorrent(videoPath, options, function (err, torrent) { if (err) return callback(err) - fs.writeFile(torrentsDir + video.filename + '.torrent', torrent, function (err) { + fs.writeFile(constants.CONFIG.STORAGE.TORRENTS_DIR + video.filename + '.torrent', torrent, function (err) { if (err) return callback(err) const parsedTorrent = parseTorrent(torrent) @@ -218,8 +218,8 @@ function listByUrlAndMagnet (fromUrl, magnetUri, callback) { this.find({ podUrl: fromUrl, magnetUri: magnetUri }, callback) } -function listByUrls (fromUrls, callback) { - this.find({ podUrl: { $in: fromUrls } }, callback) +function listByUrl (fromUrl, callback) { + this.find({ podUrl: fromUrl }, callback) } function listOwned (callback) { @@ -258,12 +258,12 @@ function removeThumbnail (video, callback) { } function removeFile (video, callback) { - fs.unlink(constants.CONFIG.STORAGE.UPLOAD_DIR + video.filename, callback) + fs.unlink(constants.CONFIG.STORAGE.VIDEOS_DIR + video.filename, callback) } // Maybe the torrent is not seeded, but we catch the error to don't stop the removing process function removeTorrent (video, callback) { - fs.unlink(torrentsDir + video.filename + '.torrent') + fs.unlink(constants.CONFIG.STORAGE.TORRENTS_DIR + video.filename + '.torrent', callback) } function createThumbnail (videoPath, callback) {