From 98ac898a03ed7bbb4edec74fe823b3f2d6d4904a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 29 Dec 2016 11:17:11 +0100 Subject: Server: use video hook to send information to other pods when a video is deleted --- server/controllers/api/pods.js | 2 +- server/controllers/api/users.js | 32 ++------------------------------ server/controllers/api/videos.js | 24 ++++++------------------ 3 files changed, 9 insertions(+), 49 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/pods.js b/server/controllers/api/pods.js index 79f3f9d8d..d9279f1d9 100644 --- a/server/controllers/api/pods.js +++ b/server/controllers/api/pods.js @@ -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) { diff --git a/server/controllers/api/users.js b/server/controllers/api/users.js index 890028b36..e4423680c 100644 --- a/server/controllers/api/users.js +++ b/server/controllers/api/users.js @@ -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) { diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js index 170224634..ddf85d77d 100644 --- a/server/controllers/api/videos.js +++ b/server/controllers/api/videos.js @@ -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) { -- cgit v1.2.3