aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/friends.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/friends.js')
-rw-r--r--server/lib/friends.js20
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')
9const constants = require('../initializers/constants') 9const constants = require('../initializers/constants')
10const logger = require('../helpers/logger') 10const logger = require('../helpers/logger')
11const peertubeCrypto = require('../helpers/peertubeCrypto') 11const peertubeCrypto = require('../helpers/peertubeCrypto')
12const Pods = require('../models/pods')
13const requests = require('../helpers/requests') 12const requests = require('../helpers/requests')
14 13
15const http = config.get('webserver.https') ? 'https' : 'http' 14const http = config.get('webserver.https') ? 'https' : 'http'
16const host = config.get('webserver.host') 15const host = config.get('webserver.host')
17const port = config.get('webserver.port') 16const port = config.get('webserver.port')
17const Pod = mongoose.model('Pod')
18const Request = mongoose.model('Request') 18const Request = mongoose.model('Request')
19const Video = mongoose.model('Video') 19const Video = mongoose.model('Video')
20 20
21const pods = { 21const 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
35function hasFriends (callback) { 35function 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
163module.exports = pods 163module.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)