'use strict'
-const each = require('async/each')
const express = require('express')
const mongoose = require('mongoose')
const waterfall = require('async/waterfall')
const router = express.Router()
const Pod = mongoose.model('Pod')
-const Video = mongoose.model('Video')
router.get('/', listPods)
router.post('/',
},
function removePod (pod, callback) {
- pod.remove(function (err) {
- // Be sure we only return one argument in the callback
- return callback(err)
- })
- },
-
- function (callback) {
- Video.listByUrls([ url ], function (err, videosList) {
- if (err) {
- logger.error('Cannot list videos from url.', { error: err })
- return callback(err)
- }
-
- return callback(null, videosList)
- })
- },
-
- function removeTheRemoteVideos (videosList, callback) {
- each(videosList, function (video, callbackEach) {
- video.remove(callbackEach)
- }, callback)
+ pod.remove(callback)
}
], function (err) {
if (err) return next(err)
require('../models/oauth-token')
require('../models/user')
require('../models/oauth-client')
-require('../models/pods')
require('../models/video')
// Request model needs Video model
+require('../models/pods')
+// Request model needs Pod model
require('../models/request')
const database = {
// Don't stop the process
}
- return callbackAsync()
+ return callbackAsync(null, pods)
})
},
- function removePodsFromDB (callbackAsync) {
- Pod.removeAll(function (err) {
- return callbackAsync(err)
- })
- },
-
- function listRemoteVideos (callbackAsync) {
- logger.info('Broke friends, so sad :(')
-
- Video.listRemotes(callbackAsync)
- },
-
- function removeTheRemoteVideos (videosList, callbackAsync) {
- each(videosList, function (video, callbackEach) {
- video.remove(callbackEach)
+ function removePodsFromDB (pods, callbackAsync) {
+ each(pods, function (pod, callbackEach) {
+ pod.remove(callbackEach)
}, callbackAsync)
}
], function (err) {
'use strict'
+const each = require('async/each')
const mongoose = require('mongoose')
const map = require('lodash/map')
const validator = require('express-validator').validator
const constants = require('../initializers/constants')
+const Video = mongoose.model('Video')
+
// ---------------------------------------------------------------------------
const PodSchema = mongoose.Schema({
})
})
+PodSchema.pre('remove', function (next) {
+ // Remove the videos owned by this pod too
+ Video.listByUrl(this.url, function (err, videos) {
+ if (err) return next(err)
+
+ each(videos, function (video, callbackEach) {
+ video.remove(callbackEach)
+ }, next)
+ })
+})
+
const Pod = mongoose.model('Pod', PodSchema)
// ------------------------------ METHODS ------------------------------
const each = require('async/each')
const eachLimit = require('async/eachLimit')
-const map = require('lodash/map')
const mongoose = require('mongoose')
const waterfall = require('async/waterfall')
const requests = require('../helpers/requests')
const Pod = mongoose.model('Pod')
-const Video = mongoose.model('Video')
let timer = null
let lastRequestTimestamp = 0
})
},
- function listVideosOfTheseBadPods (pods, callback) {
- if (pods.length === 0) return callback(null)
-
- const urls = map(pods, 'url')
-
- Video.listByUrls(urls, function (err, videosList) {
- if (err) {
- logger.error('Cannot list videos urls.', { error: err, urls: urls })
- return callback(null, pods, [])
- }
-
- return callback(null, pods, videosList)
- })
- },
-
- function removeVideosOfTheseBadPods (pods, videosList, callback) {
- // We don't have to remove pods, skip
- if (typeof pods === 'function') {
- callback = pods
- return callback(null)
- }
-
- each(videosList, function (video, callbackEach) {
- video.remove(callbackEach)
- }, function (err) {
- if (err) {
- // Don't stop the process
- logger.error('Error while removing videos of bad pods.', { error: err })
- return
- }
-
- return callback(null, pods)
- })
- },
-
- function removeBadPodsFromDB (pods, callback) {
- // We don't have to remove pods, skip
- if (typeof pods === 'function') {
- callback = pods
- return callback(null)
- }
+ function removeTheseBadPods (pods, callback) {
+ if (pods.length === 0) return callback(null, 0)
each(pods, function (pod, callbackEach) {
pod.remove(callbackEach)
}, function (err) {
- if (err) return callback(err)
-
- return callback(null, pods.length)
+ return callback(err, pods.length)
})
}
], function (err, numberOfPodsRemoved) {
getDurationFromFile,
listForApi,
listByUrlAndMagnet,
- listByUrls,
+ listByUrl,
listOwned,
listOwnedByAuthor,
listRemotes,
this.find({ podUrl: fromUrl, magnetUri: magnetUri }, callback)
}
-function listByUrls (fromUrls, callback) {
- this.find({ podUrl: { $in: fromUrls } }, callback)
+function listByUrl (fromUrl, callback) {
+ this.find({ podUrl: fromUrl }, callback)
}
function listOwned (callback) {