From e861452fb26553177ad4e32bfb18b4fd8a5b1816 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 19 Aug 2016 21:34:51 +0200 Subject: Server: put config in constants --- server/lib/friends.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'server/lib/friends.js') diff --git a/server/lib/friends.js b/server/lib/friends.js index 6e1516b94..6a2c37fd7 100644 --- a/server/lib/friends.js +++ b/server/lib/friends.js @@ -11,12 +11,8 @@ const waterfall = require('async/waterfall') const constants = require('../initializers/constants') const logger = require('../helpers/logger') -const peertubeCrypto = require('../helpers/peertube-crypto') const requests = require('../helpers/requests') -const http = config.get('webserver.https') ? 'https' : 'http' -const host = config.get('webserver.host') -const port = config.get('webserver.port') const Pod = mongoose.model('Pod') const Request = mongoose.model('Request') const Video = mongoose.model('Video') @@ -45,7 +41,7 @@ function hasFriends (callback) { } function getMyCertificate (callback) { - fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', callback) + fs.readFile(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.pub', 'utf8', callback) } function makeFriends (callback) { @@ -220,7 +216,7 @@ function makeRequestsToWinningPods (cert, podsList, callback) { url: pod.url + '/api/' + constants.API_VERSION + '/pods/', method: 'POST', json: { - url: http + '://' + host + ':' + port, + url: constants.CONFIG.WEBSERVER.URL, publicKey: cert } } -- cgit v1.2.3 From 1e2564d3927ce4ca4ca9a09930da6da7ebb4e9a1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 20 Aug 2016 16:59:25 +0200 Subject: Server: make friends urls come from the request instead of the configuration file --- server/lib/friends.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'server/lib/friends.js') diff --git a/server/lib/friends.js b/server/lib/friends.js index 6a2c37fd7..667055d4c 100644 --- a/server/lib/friends.js +++ b/server/lib/friends.js @@ -1,6 +1,5 @@ 'use strict' -const config = require('config') const each = require('async/each') const eachLimit = require('async/eachLimit') const eachSeries = require('async/eachSeries') @@ -44,7 +43,7 @@ function getMyCertificate (callback) { fs.readFile(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.pub', 'utf8', callback) } -function makeFriends (callback) { +function makeFriends (urls, callback) { const podsScore = {} logger.info('Make friends!') @@ -54,8 +53,6 @@ function makeFriends (callback) { return callback(err) } - const urls = config.get('network.friends') - eachSeries(urls, function (url, callbackEach) { computeForeignPodsList(url, podsScore, callbackEach) }, function (err) { -- cgit v1.2.3 From 39f87cb21689a912559d0498641db7d2de4a784d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Aug 2016 14:37:36 +0200 Subject: Server: catch JSON.parse exceptions --- server/lib/friends.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'server/lib/friends.js') diff --git a/server/lib/friends.js b/server/lib/friends.js index 667055d4c..6c4383d8e 100644 --- a/server/lib/friends.js +++ b/server/lib/friends.js @@ -198,7 +198,12 @@ function getForeignPodsList (url, callback) { request.get(url + path, function (err, response, body) { if (err) return callback(err) - callback(null, JSON.parse(body)) + try { + const json = JSON.parse(body) + return callback(null, json) + } catch (err) { + return callback(err) + } }) } -- cgit v1.2.3 From c4403b29ad4db097af528a7f04eea07e0ed320d0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 2 Oct 2016 12:19:02 +0200 Subject: Server: remove useless hash affectations --- server/lib/friends.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'server/lib/friends.js') diff --git a/server/lib/friends.js b/server/lib/friends.js index 6c4383d8e..556d2e773 100644 --- a/server/lib/friends.js +++ b/server/lib/friends.js @@ -17,13 +17,13 @@ const Request = mongoose.model('Request') const Video = mongoose.model('Video') const friends = { - addVideoToFriends: addVideoToFriends, - hasFriends: hasFriends, - getMyCertificate: getMyCertificate, - makeFriends: makeFriends, - quitFriends: quitFriends, - removeVideoToFriends: removeVideoToFriends, - sendOwnedVideosToPod: sendOwnedVideosToPod + addVideoToFriends, + hasFriends, + getMyCertificate, + makeFriends, + quitFriends, + removeVideoToFriends, + sendOwnedVideosToPod } function addVideoToFriends (video) { -- cgit v1.2.3