}
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))
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')
VideoSchema.statics = {
getDurationFromFile: getDurationFromFile,
- list: list,
+ listForApi: listForApi,
listByUrlAndMagnet: listByUrlAndMagnet,
listByUrls: listByUrls,
listOwned: listOwned,
})
}
-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) {
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) {
// ---------------------------------------------------------------------------
-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)
}