aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/requests.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-06-18 16:13:54 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-06-18 16:13:54 +0200
commit528a9efa8272532bbd0dafc35c3e05e57c50f61e (patch)
tree62d4417df4ab9b2e53c44dc7271be81b88e4e0e5 /server/models/requests.js
parentb2e4c0ba1a33b8a50491a1f8d111468a7da5640f (diff)
downloadPeerTube-528a9efa8272532bbd0dafc35c3e05e57c50f61e.tar.gz
PeerTube-528a9efa8272532bbd0dafc35c3e05e57c50f61e.tar.zst
PeerTube-528a9efa8272532bbd0dafc35c3e05e57c50f61e.zip
Try to make a better communication (between pods) module
Diffstat (limited to 'server/models/requests.js')
-rw-r--r--server/models/requests.js32
1 files changed, 25 insertions, 7 deletions
diff --git a/server/models/requests.js b/server/models/requests.js
index 2152ae0e9..e67ccad56 100644
--- a/server/models/requests.js
+++ b/server/models/requests.js
@@ -7,9 +7,8 @@ const logger = require('../helpers/logger')
7// --------------------------------------------------------------------------- 7// ---------------------------------------------------------------------------
8 8
9const requestsSchema = mongoose.Schema({ 9const requestsSchema = mongoose.Schema({
10 type: String, 10 request: mongoose.Schema.Types.Mixed,
11 id: String, // Special id to find duplicates (video created we want to remove...) 11 to: [ { type: mongoose.Schema.Types.ObjectId, ref: 'users' } ]
12 request: mongoose.Schema.Types.Mixed
13}) 12})
14const RequestsDB = mongoose.model('requests', requestsSchema) 13const RequestsDB = mongoose.model('requests', requestsSchema)
15 14
@@ -19,12 +18,15 @@ const Requests = {
19 create: create, 18 create: create,
20 findById: findById, 19 findById: findById,
21 list: list, 20 list: list,
21 removeAll: removeAll,
22 removePodOf: removePodOf,
22 removeRequestById: removeRequestById, 23 removeRequestById: removeRequestById,
23 removeRequests: removeRequests 24 removeRequests: removeRequests,
25 removeWithEmptyTo: removeWithEmptyTo
24} 26}
25 27
26function create (id, type, request, callback) { 28function create (request, to, callback) {
27 RequestsDB.create({ id: id, type: type, request: request }, callback) 29 RequestsDB.create({ request: request, to: to }, callback)
28} 30}
29 31
30function findById (id, callback) { 32function findById (id, callback) {
@@ -32,7 +34,17 @@ function findById (id, callback) {
32} 34}
33 35
34function list (callback) { 36function list (callback) {
35 RequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback) 37 RequestsDB.find({}, { _id: 1, request: 1, to: 1 }, callback)
38}
39
40function removeAll (callback) {
41 RequestsDB.remove({ }, callback)
42}
43
44function removePodOf (requestsIds, podId, callback) {
45 if (!callback) callback = function () {}
46
47 RequestsDB.update({ _id: { $in: requestsIds } }, { $pull: { to: podId } }, { multi: true }, callback)
36} 48}
37 49
38function removeRequestById (id, callback) { 50function removeRequestById (id, callback) {
@@ -50,6 +62,12 @@ function removeRequests (ids) {
50 }) 62 })
51} 63}
52 64
65function removeWithEmptyTo (callback) {
66 if (!callback) callback = function () {}
67
68 RequestsDB.remove({ to: { $size: 0 } }, callback)
69}
70
53// --------------------------------------------------------------------------- 71// ---------------------------------------------------------------------------
54 72
55module.exports = Requests 73module.exports = Requests