aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video.js28
1 files changed, 5 insertions, 23 deletions
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')
11const constants = require('../initializers/constants') 11const constants = require('../initializers/constants')
12const customVideosValidators = require('../helpers/custom-validators').videos 12const customVideosValidators = require('../helpers/custom-validators').videos
13const logger = require('../helpers/logger') 13const logger = require('../helpers/logger')
14const modelUtils = require('./utils')
14const utils = require('../helpers/utils') 15const utils = require('../helpers/utils')
15const webtorrent = require('../lib/webtorrent') 16const webtorrent = require('../lib/webtorrent')
16 17
@@ -60,7 +61,7 @@ VideoSchema.methods = {
60 61
61VideoSchema.statics = { 62VideoSchema.statics = {
62 getDurationFromFile: getDurationFromFile, 63 getDurationFromFile: getDurationFromFile,
63 list: list, 64 listForApi: listForApi,
64 listByUrlAndMagnet: listByUrlAndMagnet, 65 listByUrlAndMagnet: listByUrlAndMagnet,
65 listByUrls: listByUrls, 66 listByUrls: listByUrls,
66 listOwned: listOwned, 67 listOwned: listOwned,
@@ -194,9 +195,9 @@ function getDurationFromFile (videoPath, callback) {
194 }) 195 })
195} 196}
196 197
197function list (start, count, sort, callback) { 198function listForApi (start, count, sort, callback) {
198 const query = {} 199 const query = {}
199 return findWithCount.call(this, query, start, count, sort, callback) 200 return modelUtils.findWithCount.call(this, query, start, count, sort, callback)
200} 201}
201 202
202function listByUrlAndMagnet (fromUrl, magnetUri, callback) { 203function listByUrlAndMagnet (fromUrl, magnetUri, callback) {
@@ -233,7 +234,7 @@ function search (value, field, start, count, sort, callback) {
233 query[field] = new RegExp(value) 234 query[field] = new RegExp(value)
234 } 235 }
235 236
236 findWithCount.call(this, query, start, count, sort, callback) 237 modelUtils.findWithCount.call(this, query, start, count, sort, callback)
237} 238}
238 239
239function seedAllExisting (callback) { 240function seedAllExisting (callback) {
@@ -249,25 +250,6 @@ function seedAllExisting (callback) {
249 250
250// --------------------------------------------------------------------------- 251// ---------------------------------------------------------------------------
251 252
252function findWithCount (query, start, count, sort, callback) {
253 const self = this
254
255 parallel([
256 function (asyncCallback) {
257 self.find(query).skip(start).limit(count).sort(sort).exec(asyncCallback)
258 },
259 function (asyncCallback) {
260 self.count(query, asyncCallback)
261 }
262 ], function (err, results) {
263 if (err) return callback(err)
264
265 const videos = results[0]
266 const totalVideos = results[1]
267 return callback(null, videos, totalVideos)
268 })
269}
270
271function removeThumbnail (video, callback) { 253function removeThumbnail (video, callback) {
272 fs.unlink(thumbnailsDir + video.thumbnail, callback) 254 fs.unlink(thumbnailsDir + video.thumbnail, callback)
273} 255}