From 0ff21c1c086f907612e34880f76f08bc74eeb78c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 16 Aug 2016 21:51:04 +0200 Subject: Server: video.list -> video.listForApi (with pagination, sort...) --- server/models/video.js | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'server/models') diff --git a/server/models/video.js b/server/models/video.js index 14bc91b16..a5540d127 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) } -- cgit v1.2.3