aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/api/pods.js2
-rw-r--r--server/controllers/api/users.js32
-rw-r--r--server/controllers/api/videos.js24
-rw-r--r--server/models/video.js14
4 files changed, 23 insertions, 49 deletions
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) {
113 db.Pod.loadByHost(host, callback) 113 db.Pod.loadByHost(host, callback)
114 }, 114 },
115 115
116 function removePod (pod, callback) { 116 function deletePod (pod, callback) {
117 pod.destroy().asCallback(callback) 117 pod.destroy().asCallback(callback)
118 } 118 }
119 ], function (err) { 119 ], 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) {
90 90
91function removeUser (req, res, next) { 91function removeUser (req, res, next) {
92 waterfall([ 92 waterfall([
93 function getUser (callback) { 93 function loadUser (callback) {
94 db.User.loadById(req.params.id, callback) 94 db.User.loadById(req.params.id, callback)
95 }, 95 },
96 96
97 // TODO: use foreignkey? 97 function deleteUser (user, callback) {
98 function getVideos (user, callback) {
99 db.Video.listOwnedByAuthor(user.username, function (err, videos) {
100 return callback(err, user, videos)
101 })
102 },
103
104 function removeVideosFromDB (user, videos, callback) {
105 each(videos, function (video, callbackEach) {
106 video.destroy().asCallback(callbackEach)
107 }, function (err) {
108 return callback(err, user, videos)
109 })
110 },
111
112 function sendInformationToFriends (user, videos, callback) {
113 videos.forEach(function (video) {
114 const params = {
115 name: video.name,
116 remoteId: video.id
117 }
118
119 friends.removeVideoToFriends(params)
120 })
121
122 return callback(null, user)
123 },
124
125 function removeUserFromDB (user, callback) {
126 user.destroy().asCallback(callback) 98 user.destroy().asCallback(callback)
127 } 99 }
128 ], function andFinally (err) { 100 ], 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) {
249 const videoId = req.params.id 249 const videoId = req.params.id
250 250
251 waterfall([ 251 waterfall([
252 function getVideo (callback) { 252 function loadVideo (callback) {
253 db.Video.load(videoId, callback) 253 db.Video.load(videoId, function (err, video) {
254 }, 254 return callback(err, video)
255
256 function removeFromDB (video, callback) {
257 video.destroy().asCallback(function (err) {
258 if (err) return callback(err)
259
260 return callback(null, video)
261 }) 255 })
262 }, 256 },
263 257
264 function sendInformationToFriends (video, callback) { 258 function deleteVideo (video, callback) {
265 const params = { 259 // Informations to other pods will be sent by the afterDestroy video hook
266 name: video.name, 260 video.destroy().asCallback(callback)
267 remoteId: video.id
268 }
269
270 friends.removeVideoToFriends(params)
271
272 return callback(null)
273 } 261 }
274 ], function andFinally (err) { 262 ], function andFinally (err) {
275 if (err) { 263 if (err) {
diff --git a/server/models/video.js b/server/models/video.js
index d1595ce51..564e362fd 100644
--- a/server/models/video.js
+++ b/server/models/video.js
@@ -12,6 +12,7 @@ const values = require('lodash/values')
12 12
13const constants = require('../initializers/constants') 13const constants = require('../initializers/constants')
14const logger = require('../helpers/logger') 14const logger = require('../helpers/logger')
15const friends = require('../lib/friends')
15const modelUtils = require('./utils') 16const modelUtils = require('./utils')
16const customVideosValidators = require('../helpers/custom-validators').videos 17const customVideosValidators = require('../helpers/custom-validators').videos
17 18
@@ -205,11 +206,24 @@ function afterDestroy (video, options, next) {
205 function (callback) { 206 function (callback) {
206 removeFile(video, callback) 207 removeFile(video, callback)
207 }, 208 },
209
208 function (callback) { 210 function (callback) {
209 removeTorrent(video, callback) 211 removeTorrent(video, callback)
210 }, 212 },
213
211 function (callback) { 214 function (callback) {
212 removePreview(video, callback) 215 removePreview(video, callback)
216 },
217
218 function (callback) {
219 const params = {
220 name: video.name,
221 remoteId: video.id
222 }
223
224 friends.removeVideoToFriends(params)
225
226 return callback()
213 } 227 }
214 ) 228 )
215 } 229 }