X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo.js;h=1feefe24fa7667bd49f9df76f048ba9db65cc8d2;hb=80a6c9e76fda57f01e37fe4620771ae70738a211;hp=9272bea6dc99c7886f57256df66c5226f56cb63b;hpb=bf94b6f0a1ac2cd5304f5cc7f85434120489cab8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video.js b/server/models/video.js index 9272bea6d..1feefe24f 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,11 +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 webseedBaseUrl = http + '://' + host + ':' + port + constants.STATIC_PATHS.WEBSEED - // --------------------------------------------------------------------------- // TODO: add indexes on searchable columns @@ -63,7 +57,7 @@ VideoSchema.statics = { getDurationFromFile, listForApi, listByUrlAndMagnet, - listByUrls, + listByUrl, listOwned, listOwnedByAuthor, listRemotes, @@ -106,7 +100,16 @@ VideoSchema.pre('save', function (next) { 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(constants.CONFIG.STORAGE.TORRENTS_DIR + video.filename + '.torrent', torrent, function (err) { @@ -215,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) {