mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-26 02:30:37 -06:00
Server: video.list -> video.listForApi (with pagination, sort...)
This commit is contained in:
parent
7eef95353f
commit
0ff21c1c08
@ -142,7 +142,7 @@ function getVideo (req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function listVideos (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)
|
if (err) return next(err)
|
||||||
|
|
||||||
res.json(getFormatedVideos(videosList, videosTotal))
|
res.json(getFormatedVideos(videosList, videosTotal))
|
||||||
|
@ -11,6 +11,7 @@ const mongoose = require('mongoose')
|
|||||||
const constants = require('../initializers/constants')
|
const constants = require('../initializers/constants')
|
||||||
const customVideosValidators = require('../helpers/custom-validators').videos
|
const customVideosValidators = require('../helpers/custom-validators').videos
|
||||||
const logger = require('../helpers/logger')
|
const logger = require('../helpers/logger')
|
||||||
|
const modelUtils = require('./utils')
|
||||||
const utils = require('../helpers/utils')
|
const utils = require('../helpers/utils')
|
||||||
const webtorrent = require('../lib/webtorrent')
|
const webtorrent = require('../lib/webtorrent')
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ VideoSchema.methods = {
|
|||||||
|
|
||||||
VideoSchema.statics = {
|
VideoSchema.statics = {
|
||||||
getDurationFromFile: getDurationFromFile,
|
getDurationFromFile: getDurationFromFile,
|
||||||
list: list,
|
listForApi: listForApi,
|
||||||
listByUrlAndMagnet: listByUrlAndMagnet,
|
listByUrlAndMagnet: listByUrlAndMagnet,
|
||||||
listByUrls: listByUrls,
|
listByUrls: listByUrls,
|
||||||
listOwned: listOwned,
|
listOwned: listOwned,
|
||||||
@ -194,9 +195,9 @@ function getDurationFromFile (videoPath, callback) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function list (start, count, sort, callback) {
|
function listForApi (start, count, sort, callback) {
|
||||||
const query = {}
|
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) {
|
function listByUrlAndMagnet (fromUrl, magnetUri, callback) {
|
||||||
@ -233,7 +234,7 @@ function search (value, field, start, count, sort, callback) {
|
|||||||
query[field] = new RegExp(value)
|
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 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) {
|
function removeThumbnail (video, callback) {
|
||||||
fs.unlink(thumbnailsDir + video.thumbnail, callback)
|
fs.unlink(thumbnailsDir + video.thumbnail, callback)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user