diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/friends.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/server/lib/friends.js b/server/lib/friends.js index 617cc1ab4..a93467c13 100644 --- a/server/lib/friends.js +++ b/server/lib/friends.js | |||
@@ -9,16 +9,16 @@ const request = require('request') | |||
9 | const constants = require('../initializers/constants') | 9 | const constants = require('../initializers/constants') |
10 | const logger = require('../helpers/logger') | 10 | const logger = require('../helpers/logger') |
11 | const peertubeCrypto = require('../helpers/peertubeCrypto') | 11 | const peertubeCrypto = require('../helpers/peertubeCrypto') |
12 | const Pods = require('../models/pods') | ||
13 | const requests = require('../helpers/requests') | 12 | const requests = require('../helpers/requests') |
14 | 13 | ||
15 | const http = config.get('webserver.https') ? 'https' : 'http' | 14 | const http = config.get('webserver.https') ? 'https' : 'http' |
16 | const host = config.get('webserver.host') | 15 | const host = config.get('webserver.host') |
17 | const port = config.get('webserver.port') | 16 | const port = config.get('webserver.port') |
17 | const Pod = mongoose.model('Pod') | ||
18 | const Request = mongoose.model('Request') | 18 | const Request = mongoose.model('Request') |
19 | const Video = mongoose.model('Video') | 19 | const Video = mongoose.model('Video') |
20 | 20 | ||
21 | const pods = { | 21 | const friends = { |
22 | addVideoToFriends: addVideoToFriends, | 22 | addVideoToFriends: addVideoToFriends, |
23 | hasFriends: hasFriends, | 23 | hasFriends: hasFriends, |
24 | getMyCertificate: getMyCertificate, | 24 | getMyCertificate: getMyCertificate, |
@@ -33,7 +33,7 @@ function addVideoToFriends (video) { | |||
33 | } | 33 | } |
34 | 34 | ||
35 | function hasFriends (callback) { | 35 | function hasFriends (callback) { |
36 | Pods.count(function (err, count) { | 36 | Pod.countAll(function (err, count) { |
37 | if (err) return callback(err) | 37 | if (err) return callback(err) |
38 | 38 | ||
39 | const hasFriends = (count !== 0) | 39 | const hasFriends = (count !== 0) |
@@ -79,7 +79,7 @@ function quitFriends (callback) { | |||
79 | 79 | ||
80 | async.waterfall([ | 80 | async.waterfall([ |
81 | function getPodsList (callbackAsync) { | 81 | function getPodsList (callbackAsync) { |
82 | return Pods.list(callbackAsync) | 82 | return Pod.list(callbackAsync) |
83 | }, | 83 | }, |
84 | 84 | ||
85 | function announceIQuitMyFriends (pods, callbackAsync) { | 85 | function announceIQuitMyFriends (pods, callbackAsync) { |
@@ -106,7 +106,7 @@ function quitFriends (callback) { | |||
106 | }, | 106 | }, |
107 | 107 | ||
108 | function removePodsFromDB (callbackAsync) { | 108 | function removePodsFromDB (callbackAsync) { |
109 | Pods.removeAll(function (err) { | 109 | Pod.removeAll(function (err) { |
110 | return callbackAsync(err) | 110 | return callbackAsync(err) |
111 | }) | 111 | }) |
112 | }, | 112 | }, |
@@ -160,7 +160,7 @@ function sendOwnedVideosToPod (podId) { | |||
160 | 160 | ||
161 | // --------------------------------------------------------------------------- | 161 | // --------------------------------------------------------------------------- |
162 | 162 | ||
163 | module.exports = pods | 163 | module.exports = friends |
164 | 164 | ||
165 | // --------------------------------------------------------------------------- | 165 | // --------------------------------------------------------------------------- |
166 | 166 | ||
@@ -230,8 +230,12 @@ function makeRequestsToWinningPods (cert, podsList, callback) { | |||
230 | } | 230 | } |
231 | 231 | ||
232 | if (res.statusCode === 200) { | 232 | if (res.statusCode === 200) { |
233 | Pods.add({ url: pod.url, publicKey: body.cert, score: constants.FRIEND_BASE_SCORE }, function (err, podCreated) { | 233 | const podObj = new Pod({ url: pod.url, publicKey: body.cert }) |
234 | if (err) logger.error('Cannot add friend %s pod.', pod.url) | 234 | podObj.save(function (err, podCreated) { |
235 | if (err) { | ||
236 | logger.error('Cannot add friend %s pod.', pod.url, { error: err }) | ||
237 | return callbackEach() | ||
238 | } | ||
235 | 239 | ||
236 | // Add our videos to the request scheduler | 240 | // Add our videos to the request scheduler |
237 | sendOwnedVideosToPod(podCreated._id) | 241 | sendOwnedVideosToPod(podCreated._id) |