var uploadDir = path.join(__dirname, '..', '..', config.get('storage.uploads'))
var videos = {
+ getVideoState: getVideoState,
seed: seed,
seedAllExisting: seedAllExisting
}
+function getVideoState (video, callback) {
+ var exist = (video !== null)
+ var owned = false
+ if (exist === true) {
+ owned = (video.namePath !== null)
+ }
+
+ return callback({ exist: exist, owned: owned })
+}
+
function seed (path, callback) {
logger.info('Seeding %s...', path)
var checkErrors = require('./utils').checkErrors
var logger = require('../../helpers/logger')
+var videos = require('../../lib/videos')
var Videos = require('../../models/videos')
var reqValidatorsVideos = {
logger.debug('Checking videosGet parameters', { parameters: req.params })
checkErrors(req, res, function () {
- Videos.getVideoState(req.params.id, function (err, state) {
+ Videos.get(req.params.id, function (err, video) {
if (err) {
logger.error('Error in videosGet request validator.', { error: err })
res.sendStatus(500)
}
- if (state.exist === false) return res.status(404).send('Video not found')
+ videos.getVideoState(video, function (state) {
+ if (state.exist === false) return res.status(404).send('Video not found')
- next()
+ next()
+ })
})
})
}
logger.debug('Checking videosRemove parameters', { parameters: req.params })
checkErrors(req, res, function () {
- Videos.getVideoState(req.params.id, function (err, state) {
+ Videos.get(req.params.id, function (err, video) {
if (err) {
logger.error('Error in videosRemove request validator.', { error: err })
res.sendStatus(500)
}
- if (state.exist === false) return res.status(404).send('Video not found')
- else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod')
+ videos.getVideoState(video, function (state) {
+ if (state.exist === false) return res.status(404).send('Video not found')
+ else if (state.owned === false) return res.status(403).send('Cannot remove video of another pod')
- next()
+ next()
+ })
})
})
}
add: add,
addRemotes: addRemotes,
get: get,
- getVideoState: getVideoState,
- isOwned: isOwned,
list: list,
listOwned: listOwned,
removeOwned: removeOwned,
})
}
-function getVideoState (id, callback) {
- get(id, function (err, video) {
- if (err) return callback(err)
-
- var exist = (video !== null)
- var owned = false
- if (exist === true) {
- owned = (video.namePath !== null)
- }
-
- return callback(null, { exist: exist, owned: owned })
- })
-}
-
-function isOwned (id, callback) {
- VideosDB.findById(id, function (err, video) {
- if (err || !video) {
- if (!err) err = new Error('Cannot find this video.')
- logger.error('Cannot find this video.')
- return callback(err)
- }
-
- if (video.namePath === null) {
- var error_string = 'Cannot remove the video of another pod.'
- logger.error(error_string)
- return callback(new Error(error_string), false, video)
- }
-
- callback(null, true, video)
- })
-}
-
function list (callback) {
VideosDB.find(function (err, videos_list) {
if (err) {