Server: use video hook to send information to other pods when a video is
deleted
This commit is contained in:
parent
4712081f2a
commit
98ac898a03
|
@ -113,7 +113,7 @@ function removePods (req, res, next) {
|
|||
db.Pod.loadByHost(host, callback)
|
||||
},
|
||||
|
||||
function removePod (pod, callback) {
|
||||
function deletePod (pod, callback) {
|
||||
pod.destroy().asCallback(callback)
|
||||
}
|
||||
], function (err) {
|
||||
|
|
|
@ -90,39 +90,11 @@ function listUsers (req, res, next) {
|
|||
|
||||
function removeUser (req, res, next) {
|
||||
waterfall([
|
||||
function getUser (callback) {
|
||||
function loadUser (callback) {
|
||||
db.User.loadById(req.params.id, callback)
|
||||
},
|
||||
|
||||
// TODO: use foreignkey?
|
||||
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) {
|
||||
function deleteUser (user, callback) {
|
||||
user.destroy().asCallback(callback)
|
||||
}
|
||||
], function andFinally (err) {
|
||||
|
|
|
@ -249,27 +249,15 @@ function removeVideo (req, res, next) {
|
|||
const videoId = req.params.id
|
||||
|
||||
waterfall([
|
||||
function getVideo (callback) {
|
||||
db.Video.load(videoId, callback)
|
||||
},
|
||||
|
||||
function removeFromDB (video, callback) {
|
||||
video.destroy().asCallback(function (err) {
|
||||
if (err) return callback(err)
|
||||
|
||||
return callback(null, video)
|
||||
function loadVideo (callback) {
|
||||
db.Video.load(videoId, function (err, video) {
|
||||
return callback(err, video)
|
||||
})
|
||||
},
|
||||
|
||||
function sendInformationToFriends (video, callback) {
|
||||
const params = {
|
||||
name: video.name,
|
||||
remoteId: video.id
|
||||
}
|
||||
|
||||
friends.removeVideoToFriends(params)
|
||||
|
||||
return callback(null)
|
||||
function deleteVideo (video, callback) {
|
||||
// Informations to other pods will be sent by the afterDestroy video hook
|
||||
video.destroy().asCallback(callback)
|
||||
}
|
||||
], function andFinally (err) {
|
||||
if (err) {
|
||||
|
|
|
@ -12,6 +12,7 @@ const values = require('lodash/values')
|
|||
|
||||
const constants = require('../initializers/constants')
|
||||
const logger = require('../helpers/logger')
|
||||
const friends = require('../lib/friends')
|
||||
const modelUtils = require('./utils')
|
||||
const customVideosValidators = require('../helpers/custom-validators').videos
|
||||
|
||||
|
@ -205,11 +206,24 @@ function afterDestroy (video, options, next) {
|
|||
function (callback) {
|
||||
removeFile(video, callback)
|
||||
},
|
||||
|
||||
function (callback) {
|
||||
removeTorrent(video, callback)
|
||||
},
|
||||
|
||||
function (callback) {
|
||||
removePreview(video, callback)
|
||||
},
|
||||
|
||||
function (callback) {
|
||||
const params = {
|
||||
name: video.name,
|
||||
remoteId: video.id
|
||||
}
|
||||
|
||||
friends.removeVideoToFriends(params)
|
||||
|
||||
return callback()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue