X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fpods.js;h=9502d92e407aacc3cea530ca9defebee10109ae0;hb=d14b3e37a2c0d647b59259bf2ca059b5817f144c;hp=04cc2d6fce266ae145a162341f5eeebfc6de2082;hpb=bc503c2a62dcf9aed6b8d90b68f0f27a7755ac01;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/pods.js b/server/models/pods.js index 04cc2d6fc..9502d92e4 100644 --- a/server/models/pods.js +++ b/server/models/pods.js @@ -1,6 +1,7 @@ 'use strict' const mongoose = require('mongoose') +const map = require('lodash/map') const constants = require('../initializers/constants') const logger = require('../helpers/logger') @@ -19,10 +20,13 @@ const PodsDB = mongoose.model('pods', podsSchema) const Pods = { add: add, count: count, + findById: findById, findByUrl: findByUrl, findBadPods: findBadPods, incrementScores: incrementScores, list: list, + listAllIds: listAllIds, + listAllUrls: listAllUrls, remove: remove, removeAll: removeAll, removeAllByIds: removeAllByIds @@ -48,6 +52,10 @@ function findBadPods (callback) { PodsDB.find({ score: 0 }, callback) } +function findById (id, callback) { + PodsDB.findById(id, callback) +} + function findByUrl (url, callback) { PodsDB.findOne({ url: url }, callback) } @@ -68,6 +76,18 @@ function list (callback) { }) } +function listAllIds (callback) { + return PodsDB.find({}, { _id: 1 }, function (err, pods) { + if (err) return callback(err) + + return callback(null, map(pods, '_id')) + }) +} + +function listAllUrls (callback) { + return PodsDB.find({}, { _id: 0, url: 1 }, callback) +} + function remove (url, callback) { if (!callback) callback = function () {} PodsDB.remove({ url: url }, callback)