]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - models/pods.js
3 const mongoose
= require('mongoose')
5 const constants
= require('../initializers/constants')
6 const logger
= require('../helpers/logger')
8 // ---------------------------------------------------------------------------
10 const podsSchema
= mongoose
.Schema({
13 score: { type: Number
, max: constants
.FRIEND_BASE_SCORE
}
15 const PodsDB
= mongoose
.model('pods', podsSchema
)
17 // ---------------------------------------------------------------------------
23 findBadPods: findBadPods
,
24 incrementScores: incrementScores
,
28 removeAllByIds: removeAllByIds
31 // TODO: check if the pod is not already a friend
32 function add (data
, callback
) {
33 if (!callback
) callback = function () {}
36 publicKey: data
.publicKey
,
37 score: constants
.FRIEND_BASE_SCORE
40 PodsDB
.create(params
, callback
)
43 function count (callback
) {
44 return PodsDB
.count(callback
)
47 function findBadPods (callback
) {
48 PodsDB
.find({ score: 0 }, callback
)
51 function findByUrl (url
, callback
) {
52 PodsDB
.findOne({ url: url
}, callback
)
55 function incrementScores (ids
, value
, callback
) {
56 if (!callback
) callback = function () {}
57 PodsDB
.update({ _id: { $in: ids
} }, { $inc: { score: value
} }, { multi: true }, callback
)
60 function list (callback
) {
61 PodsDB
.find(function (err
, pods_list
) {
63 logger
.error('Cannot get the list of the pods.')
67 return callback(null, pods_list
)
71 function remove (url
, callback
) {
72 if (!callback
) callback = function () {}
73 PodsDB
.remove({ url: url
}, callback
)
76 function removeAll (callback
) {
77 if (!callback
) callback = function () {}
78 PodsDB
.remove(callback
)
81 function removeAllByIds (ids
, callback
) {
82 if (!callback
) callback = function () {}
83 PodsDB
.remove({ _id: { $in: ids
} }, callback
)
86 // ---------------------------------------------------------------------------