Re enable the "seed all videos" function
[oweals/peertube.git] / server / models / pods.js
index 57ed20292eef0cbffff4650ca6e10ab7bf36e8c8..9502d92e407aacc3cea530ca9defebee10109ae0 100644 (file)
@@ -1,28 +1,32 @@
 'use strict'
 
-var mongoose = require('mongoose')
+const mongoose = require('mongoose')
+const map = require('lodash/map')
 
-var constants = require('../initializers/constants')
-var logger = require('../helpers/logger')
+const constants = require('../initializers/constants')
+const logger = require('../helpers/logger')
 
 // ---------------------------------------------------------------------------
 
-var podsSchema = mongoose.Schema({
+const podsSchema = mongoose.Schema({
   url: String,
   publicKey: String,
   score: { type: Number, max: constants.FRIEND_BASE_SCORE }
 })
-var PodsDB = mongoose.model('pods', podsSchema)
+const PodsDB = mongoose.model('pods', podsSchema)
 
 // ---------------------------------------------------------------------------
 
-var Pods = {
+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
@@ -31,7 +35,7 @@ var Pods = {
 // TODO: check if the pod is not already a friend
 function add (data, callback) {
   if (!callback) callback = function () {}
-  var params = {
+  const params = {
     url: data.url,
     publicKey: data.publicKey,
     score: constants.FRIEND_BASE_SCORE
@@ -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)
 }
@@ -58,16 +66,28 @@ function incrementScores (ids, value, callback) {
 }
 
 function list (callback) {
-  PodsDB.find(function (err, pods_list) {
+  PodsDB.find(function (err, podsList) {
     if (err) {
       logger.error('Cannot get the list of the pods.')
       return callback(err)
     }
 
-    return callback(null, pods_list)
+    return callback(null, podsList)
+  })
+}
+
+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)