diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-13 14:27:40 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-13 14:27:40 +0200 |
commit | 90d4bb8125e80c8060416d4d135ddeaf0a622ede (patch) | |
tree | b3b7181329a08ecc930b54fe7b48095c4155393c /server/controllers/api/videos/abuse.ts | |
parent | 3cd0734fd9b0ff21aaef02317a874e8f1c06e027 (diff) | |
download | PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.tar.gz PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.tar.zst PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.zip |
Refractor retry transaction function
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 | } |