aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos.js68
1 files changed, 56 insertions, 12 deletions
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js
index 4d45c11c0..6573b1210 100644
--- a/server/controllers/api/videos.js
+++ b/server/controllers/api/videos.js
@@ -56,7 +56,7 @@ router.get('/abuse',
56router.post('/:id/abuse', 56router.post('/:id/abuse',
57 oAuth.authenticate, 57 oAuth.authenticate,
58 validatorsVideos.videoAbuseReport, 58 validatorsVideos.videoAbuseReport,
59 reportVideoAbuse 59 reportVideoAbuseRetryWrapper
60) 60)
61 61
62router.get('/', 62router.get('/',
@@ -375,7 +375,23 @@ function listVideoAbuses (req, res, next) {
375 }) 375 })
376} 376}
377 377
378function reportVideoAbuse (req, res, next) { 378function reportVideoAbuseRetryWrapper (req, res, next) {
379 utils.transactionRetryer(
380 function (callback) {
381 return reportVideoAbuse(req, res, callback)
382 },
383 function (err) {
384 if (err) {
385 logger.error('Cannot report abuse to the video with many retries.', { error: err })
386 return next(err)
387 }
388
389 return res.type('json').status(204).end()
390 }
391 )
392}
393
394function reportVideoAbuse (req, res, finalCallback) {
379 const videoInstance = res.locals.video 395 const videoInstance = res.locals.video
380 const reporterUsername = res.locals.oauth.token.User.username 396 const reporterUsername = res.locals.oauth.token.User.username
381 397
@@ -386,21 +402,49 @@ function reportVideoAbuse (req, res, next) {
386 reporterPodId: null // This is our pod that reported this abuse 402 reporterPodId: null // This is our pod that reported this abuse
387 } 403 }
388 404
389 db.VideoAbuse.create(abuse).asCallback(function (err) { 405 waterfall([
390 if (err) return next(err) 406
407 function startTransaction (callback) {
408 db.sequelize.transaction().asCallback(function (err, t) {
409 return callback(err, t)
410 })
411 },
412
413 function createAbuse (t, callback) {
414 db.VideoAbuse.create(abuse).asCallback(function (err, abuse) {
415 return callback(err, t, abuse)
416 })
417 },
418
419 function sendToFriendsIfNeeded (t, abuse, callback) {
420 // We send the information to the destination pod
421 if (videoInstance.isOwned() === false) {
422 const reportData = {
423 reporterUsername,
424 reportReason: abuse.reason,
425 videoRemoteId: videoInstance.remoteId
426 }
391 427
392 // We send the information to the destination pod 428 friends.reportAbuseVideoToFriend(reportData, videoInstance)
393 if (videoInstance.isOwned() === false) {
394 const reportData = {
395 reporterUsername,
396 reportReason: abuse.reason,
397 videoRemoteId: videoInstance.remoteId
398 } 429 }
399 430
400 friends.reportAbuseVideoToFriend(reportData, videoInstance) 431 return callback(null, t)
401 } 432 }
402 433
403 return res.type('json').status(204).end() 434 ], function andFinally (err, t) {
435 if (err) {
436 logger.debug('Cannot update the video.', { error: err })
437
438 // Abort transaction?
439 if (t) t.rollback()
440
441 return finalCallback(err)
442 }
443
444 // Commit transaction
445 t.commit()
446
447 return finalCallback(null)
404 }) 448 })
405} 449}
406 450