Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Server: video.list -> video.listForApi (with pagination, sort...)

Chocobozzz0ff21c1c086f
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js
index 1f939b077f..0a441f1463 100644
--- a/server/controllers/api/v1/videos.js
+++ b/server/controllers/api/v1/videos.js
@@ -142,7 +142,7 @@ function getVideo (req, res, next) {
}
function listVideos (req, res, next) {
- Video.list(req.query.start, req.query.count, req.query.sort, function (err, videosList, videosTotal) {
+ Video.listForApi(req.query.start, req.query.count, req.query.sort, function (err, videosList, videosTotal) {
if (err) return next(err)
res.json(getFormatedVideos(videosList, videosTotal))
diff --git a/server/models/video.js b/server/models/video.js
index 14bc91b16f..a5540d127a 100644
--- a/server/models/video.js
+++ b/server/models/video.js
@@ -11,6 +11,7 @@ const mongoose = require('mongoose')
const constants = require('../initializers/constants')
const customVideosValidators = require('../helpers/custom-validators').videos
const logger = require('../helpers/logger')
+const modelUtils = require('./utils')
const utils = require('../helpers/utils')
const webtorrent = require('../lib/webtorrent')
@@ -60,7 +61,7 @@ VideoSchema.methods = {
VideoSchema.statics = {
getDurationFromFile: getDurationFromFile,
- list: list,
+ listForApi: listForApi,
listByUrlAndMagnet: listByUrlAndMagnet,
listByUrls: listByUrls,
listOwned: listOwned,
@@ -194,9 +195,9 @@ function getDurationFromFile (videoPath, callback) {
})
}
-function list (start, count, sort, callback) {
+function listForApi (start, count, sort, callback) {
const query = {}
- return findWithCount.call(this, query, start, count, sort, callback)
+ return modelUtils.findWithCount.call(this, query, start, count, sort, callback)
}
function listByUrlAndMagnet (fromUrl, magnetUri, callback) {
@@ -233,7 +234,7 @@ function search (value, field, start, count, sort, callback) {
query[field] = new RegExp(value)
}
- findWithCount.call(this, query, start, count, sort, callback)
+ modelUtils.findWithCount.call(this, query, start, count, sort, callback)
}
function seedAllExisting (callback) {
@@ -249,25 +250,6 @@ function seedAllExisting (callback) {
// ---------------------------------------------------------------------------
-function findWithCount (query, start, count, sort, callback) {
- const self = this
-
- parallel([
- function (asyncCallback) {
- self.find(query).skip(start).limit(count).sort(sort).exec(asyncCallback)
- },
- function (asyncCallback) {
- self.count(query, asyncCallback)
- }
- ], function (err, results) {
- if (err) return callback(err)
-
- const videos = results[0]
- const totalVideos = results[1]
- return callback(null, videos, totalVideos)
- })
-}
-
function removeThumbnail (video, callback) {
fs.unlink(thumbnailsDir + video.thumbnail, callback)
}