aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-06-30 22:39:08 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-06-30 22:39:08 +0200
commita3ee6fa22dee4b68fcde9cd23708b471db446e11 (patch)
treeb05543f6d858c52dd4757123bc605277ede96983 /server/lib
parentd14b3e37a2c0d647b59259bf2ca059b5817f144c (diff)
downloadPeerTube-a3ee6fa22dee4b68fcde9cd23708b471db446e11.tar.gz
PeerTube-a3ee6fa22dee4b68fcde9cd23708b471db446e11.tar.zst
PeerTube-a3ee6fa22dee4b68fcde9cd23708b471db446e11.zip
Pod model refractoring -> use mongoose api
Diffstat (limited to 'server/lib')
-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)