1
0
Fork 0

Server: use video hook to send information to other pods when a video is

deleted
This commit is contained in:
Chocobozzz 2016-12-29 11:17:11 +01:00
parent 4712081f2a
commit 98ac898a03
4 changed files with 23 additions and 49 deletions

View File

@ -113,7 +113,7 @@ function removePods (req, res, next) {
db.Pod.loadByHost(host, callback) db.Pod.loadByHost(host, callback)
}, },
function removePod (pod, callback) { function deletePod (pod, callback) {
pod.destroy().asCallback(callback) pod.destroy().asCallback(callback)
} }
], function (err) { ], function (err) {

View File

@ -90,39 +90,11 @@ function listUsers (req, res, next) {
function removeUser (req, res, next) { function removeUser (req, res, next) {
waterfall([ waterfall([
function getUser (callback) { function loadUser (callback) {
db.User.loadById(req.params.id, callback) db.User.loadById(req.params.id, callback)
}, },
// TODO: use foreignkey? function deleteUser (user, callback) {
function getVideos (user, callback) {
db.Video.listOwnedByAuthor(user.username, function (err, videos) {
return callback(err, user, videos)
})
},
function removeVideosFromDB (user, videos, callback) {
each(videos, function (video, callbackEach) {
video.destroy().asCallback(callbackEach)
}, function (err) {
return callback(err, user, videos)
})
},
function sendInformationToFriends (user, videos, callback) {
videos.forEach(function (video) {
const params = {
name: video.name,
remoteId: video.id
}
friends.removeVideoToFriends(params)
})
return callback(null, user)
},
function removeUserFromDB (user, callback) {
user.destroy().asCallback(callback) user.destroy().asCallback(callback)
} }
], function andFinally (err) { ], function andFinally (err) {

View File

@ -249,27 +249,15 @@ function removeVideo (req, res, next) {
const videoId = req.params.id const videoId = req.params.id
waterfall([ waterfall([
function getVideo (callback) { function loadVideo (callback) {
db.Video.load(videoId, callback) db.Video.load(videoId, function (err, video) {
}, return callback(err, video)
function removeFromDB (video, callback) {
video.destroy().asCallback(function (err) {
if (err) return callback(err)
return callback(null, video)
}) })
}, },
function sendInformationToFriends (video, callback) { function deleteVideo (video, callback) {
const params = { // Informations to other pods will be sent by the afterDestroy video hook
name: video.name, video.destroy().asCallback(callback)
remoteId: video.id
}
friends.removeVideoToFriends(params)
return callback(null)
} }
], function andFinally (err) { ], function andFinally (err) {
if (err) { if (err) {

View File

@ -12,6 +12,7 @@ const values = require('lodash/values')
const constants = require('../initializers/constants') const constants = require('../initializers/constants')
const logger = require('../helpers/logger') const logger = require('../helpers/logger')
const friends = require('../lib/friends')
const modelUtils = require('./utils') const modelUtils = require('./utils')
const customVideosValidators = require('../helpers/custom-validators').videos const customVideosValidators = require('../helpers/custom-validators').videos
@ -205,11 +206,24 @@ function afterDestroy (video, options, next) {
function (callback) { function (callback) {
removeFile(video, callback) removeFile(video, callback)
}, },
function (callback) { function (callback) {
removeTorrent(video, callback) removeTorrent(video, callback)
}, },
function (callback) { function (callback) {
removePreview(video, callback) removePreview(video, callback)
},
function (callback) {
const params = {
name: video.name,
remoteId: video.id
}
friends.removeVideoToFriends(params)
return callback()
} }
) )
} }