diff options
Diffstat (limited to 'server/controllers/api/videos/abuse.ts')
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 25 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserRight, VideoAbuseCreate } from '../../../../shared' | 2 | import { UserRight, VideoAbuseCreate } from '../../../../shared' |
3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | ||
4 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
5 | import { getFormattedObjects } from '../../../helpers/utils' | 4 | import { getFormattedObjects } from '../../../helpers/utils' |
6 | import { sequelizeTypescript } from '../../../initializers' | 5 | import { sequelizeTypescript } from '../../../initializers' |
7 | import { sendVideoAbuse } from '../../../lib/activitypub/send' | 6 | import { sendVideoAbuse } from '../../../lib/activitypub/send' |
8 | import { | 7 | import { |
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' |
12 | import { AccountModel } from '../../../models/account/account' | 18 | import { AccountModel } from '../../../models/account/account' |
@@ -27,7 +33,7 @@ abuseVideoRouter.get('/abuse', | |||
27 | abuseVideoRouter.post('/:id/abuse', | 33 | abuseVideoRouter.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 | ||
47 | async 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 | |||
58 | async function reportVideoAbuse (req: express.Request, res: express.Response) { | 53 | async 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 | } |