aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/abuse.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos/abuse.ts')
-rw-r--r--server/controllers/api/videos/abuse.ts25
1 files changed, 11 insertions, 14 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts
index 61ff3af4f..3413ae894 100644
--- a/server/controllers/api/videos/abuse.ts
+++ b/server/controllers/api/videos/abuse.ts
@@ -1,12 +1,18 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserRight, VideoAbuseCreate } from '../../../../shared' 2import { UserRight, VideoAbuseCreate } from '../../../../shared'
3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
5import { getFormattedObjects } from '../../../helpers/utils' 4import { getFormattedObjects } from '../../../helpers/utils'
6import { sequelizeTypescript } from '../../../initializers' 5import { sequelizeTypescript } from '../../../initializers'
7import { sendVideoAbuse } from '../../../lib/activitypub/send' 6import { sendVideoAbuse } from '../../../lib/activitypub/send'
8import { 7import {
9 asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, setDefaultSort, setDefaultPagination, videoAbuseReportValidator, 8 asyncMiddleware,
9 asyncRetryTransactionMiddleware,
10 authenticate,
11 ensureUserHasRight,
12 paginationValidator,
13 setDefaultPagination,
14 setDefaultSort,
15 videoAbuseReportValidator,
10 videoAbusesSortValidator 16 videoAbusesSortValidator
11} from '../../../middlewares' 17} from '../../../middlewares'
12import { AccountModel } from '../../../models/account/account' 18import { AccountModel } from '../../../models/account/account'
@@ -27,7 +33,7 @@ abuseVideoRouter.get('/abuse',
27abuseVideoRouter.post('/:id/abuse', 33abuseVideoRouter.post('/:id/abuse',
28 authenticate, 34 authenticate,
29 asyncMiddleware(videoAbuseReportValidator), 35 asyncMiddleware(videoAbuseReportValidator),
30 asyncMiddleware(reportVideoAbuseRetryWrapper) 36 asyncRetryTransactionMiddleware(reportVideoAbuse)
31) 37)
32 38
33// --------------------------------------------------------------------------- 39// ---------------------------------------------------------------------------
@@ -44,17 +50,6 @@ async function listVideoAbuses (req: express.Request, res: express.Response, nex
44 return res.json(getFormattedObjects(resultList.data, resultList.total)) 50 return res.json(getFormattedObjects(resultList.data, resultList.total))
45} 51}
46 52
47async function reportVideoAbuseRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
48 const options = {
49 arguments: [ req, res ],
50 errorMessage: 'Cannot report abuse to the video with many retries.'
51 }
52
53 await retryTransactionWrapper(reportVideoAbuse, options)
54
55 return res.type('json').status(204).end()
56}
57
58async function reportVideoAbuse (req: express.Request, res: express.Response) { 53async function reportVideoAbuse (req: express.Request, res: express.Response) {
59 const videoInstance = res.locals.video as VideoModel 54 const videoInstance = res.locals.video as VideoModel
60 const reporterAccount = res.locals.oauth.token.User.Account as AccountModel 55 const reporterAccount = res.locals.oauth.token.User.Account as AccountModel
@@ -77,4 +72,6 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) {
77 }) 72 })
78 73
79 logger.info('Abuse report for video %s created.', videoInstance.name) 74 logger.info('Abuse report for video %s created.', videoInstance.name)
75
76 return res.type('json').status(204).end()
80} 77}