1
0
Fork 0

Server: update to webseed implementation (tests, lint...)

This commit is contained in:
Chocobozzz 2016-10-07 11:08:55 +02:00
parent 82e624233f
commit bf94b6f0a1
6 changed files with 8 additions and 23 deletions

View File

@ -69,7 +69,8 @@
"commander": "^2.9.0", "commander": "^2.9.0",
"mocha": "^3.0.1", "mocha": "^3.0.1",
"standard": "^8.0.0", "standard": "^8.0.0",
"supertest": "^2.0.0" "supertest": "^2.0.0",
"webtorrent": "^0.97.0"
}, },
"standard": { "standard": {
"ignore": [ "ignore": [

View File

@ -42,7 +42,8 @@ const CONFIG = {
CERT_DIR: path.join(__dirname, '..', '..', config.get('storage.certs')), CERT_DIR: path.join(__dirname, '..', '..', config.get('storage.certs')),
LOG_DIR: path.join(__dirname, '..', '..', config.get('storage.logs')), LOG_DIR: path.join(__dirname, '..', '..', config.get('storage.logs')),
UPLOAD_DIR: path.join(__dirname, '..', '..', config.get('storage.uploads')), UPLOAD_DIR: path.join(__dirname, '..', '..', config.get('storage.uploads')),
THUMBNAILS_DIR: path.join(__dirname, '..', '..', config.get('storage.thumbnails')) THUMBNAILS_DIR: path.join(__dirname, '..', '..', config.get('storage.thumbnails')),
TORRENTS_DIR: path.join(__dirname, '..', '..', config.get('storage.torrents'))
}, },
WEBSERVER: { WEBSERVER: {
SCHEME: config.get('webserver.https') === true ? 'https' : 'http', SCHEME: config.get('webserver.https') === true ? 'https' : 'http',

View File

@ -19,9 +19,6 @@ const utils = require('../helpers/utils')
const http = config.get('webserver.https') === true ? 'https' : 'http' const http = config.get('webserver.https') === true ? 'https' : 'http'
const host = config.get('webserver.host') const host = config.get('webserver.host')
const port = config.get('webserver.port') 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 const webseedBaseUrl = http + '://' + host + ':' + port + constants.STATIC_PATHS.WEBSEED
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -112,7 +109,7 @@ VideoSchema.pre('save', function (next) {
createTorrent(videoPath, { announceList: [ [ 'ws://' + host + ':' + port + '/tracker/socket' ] ], urlList: [ webseedBaseUrl + video.filename ] }, function (err, torrent) { createTorrent(videoPath, { announceList: [ [ 'ws://' + host + ':' + port + '/tracker/socket' ] ], urlList: [ webseedBaseUrl + video.filename ] }, function (err, torrent) {
if (err) return callback(err) 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) if (err) return callback(err)
const parsedTorrent = parseTorrent(torrent) const parsedTorrent = parseTorrent(torrent)
@ -263,7 +260,7 @@ function removeFile (video, callback) {
// Maybe the torrent is not seeded, but we catch the error to don't stop the removing process // Maybe the torrent is not seeded, but we catch the error to don't stop the removing process
function removeTorrent (video, callback) { 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) { function createThumbnail (videoPath, callback) {

View File

@ -3,16 +3,14 @@
const chai = require('chai') const chai = require('chai')
const each = require('async/each') const each = require('async/each')
const expect = chai.expect const expect = chai.expect
const pathUtils = require('path')
const series = require('async/series') const series = require('async/series')
const webtorrent = new (require('webtorrent'))()
const loginUtils = require('../utils/login') const loginUtils = require('../utils/login')
const miscsUtils = require('../utils/miscs') const miscsUtils = require('../utils/miscs')
const podsUtils = require('../utils/pods') const podsUtils = require('../utils/pods')
const serversUtils = require('../utils/servers') const serversUtils = require('../utils/servers')
const videosUtils = require('../utils/videos') const videosUtils = require('../utils/videos')
const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
webtorrent.silent = true
describe('Test multiple pods', function () { describe('Test multiple pods', function () {
let servers = [] let servers = []
@ -53,9 +51,6 @@ describe('Test multiple pods', function () {
function (next) { function (next) {
const server = servers[0] const server = servers[0]
podsUtils.makeFriends(server.url, server.accessToken, next) podsUtils.makeFriends(server.url, server.accessToken, next)
},
function (next) {
webtorrent.create({ host: 'client', port: '1' }, next)
} }
], done) ], done)
}) })
@ -415,7 +410,6 @@ describe('Test multiple pods', function () {
servers.forEach(function (server) { servers.forEach(function (server) {
process.kill(-server.app.pid) process.kill(-server.app.pid)
}) })
process.kill(-webtorrent.app.pid)
// Keep the logs if the test failed // Keep the logs if the test failed
if (this.ok) { if (this.ok) {

View File

@ -7,13 +7,12 @@ const fs = require('fs')
const keyBy = require('lodash/keyBy') const keyBy = require('lodash/keyBy')
const pathUtils = require('path') const pathUtils = require('path')
const series = require('async/series') const series = require('async/series')
const webtorrent = new (require('webtorrent'))()
const loginUtils = require('../utils/login') const loginUtils = require('../utils/login')
const miscsUtils = require('../utils/miscs') const miscsUtils = require('../utils/miscs')
const serversUtils = require('../utils/servers') const serversUtils = require('../utils/servers')
const videosUtils = require('../utils/videos') const videosUtils = require('../utils/videos')
const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
webtorrent.silent = true
describe('Test a single pod', function () { describe('Test a single pod', function () {
let server = null let server = null
@ -39,9 +38,6 @@ describe('Test a single pod', function () {
server.accessToken = token server.accessToken = token
next() next()
}) })
},
function (next) {
webtorrent.create({ host: 'client', port: '1' }, next)
} }
], done) ], done)
}) })
@ -496,7 +492,6 @@ describe('Test a single pod', function () {
after(function (done) { after(function (done) {
process.kill(-server.app.pid) process.kill(-server.app.pid)
process.kill(-webtorrent.app.pid)
// Keep the logs if the test failed // Keep the logs if the test failed
if (this.ok) { if (this.ok) {

View File

@ -2,7 +2,6 @@
const chai = require('chai') const chai = require('chai')
const expect = chai.expect const expect = chai.expect
const pathUtils = require('path')
const series = require('async/series') const series = require('async/series')
const loginUtils = require('../utils/login') const loginUtils = require('../utils/login')
@ -10,8 +9,6 @@ const podsUtils = require('../utils/pods')
const serversUtils = require('../utils/servers') const serversUtils = require('../utils/servers')
const usersUtils = require('../utils/users') const usersUtils = require('../utils/users')
const videosUtils = require('../utils/videos') const videosUtils = require('../utils/videos')
const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
webtorrent.silent = true
describe('Test users', function () { describe('Test users', function () {
let server = null let server = null