diff options
Diffstat (limited to 'server/controllers/api/videos/rate.ts')
-rw-r--r-- | server/controllers/api/videos/rate.ts | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index 23e9de9f3..9d63b5821 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts | |||
@@ -1,10 +1,9 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserVideoRateUpdate } from '../../../../shared' | 2 | import { UserVideoRateUpdate } from '../../../../shared' |
3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | ||
4 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
5 | import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers' | 4 | import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers' |
6 | import { sendVideoRateChange } from '../../../lib/activitypub' | 5 | import { sendVideoRateChange } from '../../../lib/activitypub' |
7 | import { asyncMiddleware, authenticate, videoRateValidator } from '../../../middlewares' | 6 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoRateValidator } from '../../../middlewares' |
8 | import { AccountModel } from '../../../models/account/account' | 7 | import { AccountModel } from '../../../models/account/account' |
9 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
10 | import { VideoModel } from '../../../models/video/video' | 9 | import { VideoModel } from '../../../models/video/video' |
@@ -14,7 +13,7 @@ const rateVideoRouter = express.Router() | |||
14 | rateVideoRouter.put('/:id/rate', | 13 | rateVideoRouter.put('/:id/rate', |
15 | authenticate, | 14 | authenticate, |
16 | asyncMiddleware(videoRateValidator), | 15 | asyncMiddleware(videoRateValidator), |
17 | asyncMiddleware(rateVideoRetryWrapper) | 16 | asyncRetryTransactionMiddleware(rateVideo) |
18 | ) | 17 | ) |
19 | 18 | ||
20 | // --------------------------------------------------------------------------- | 19 | // --------------------------------------------------------------------------- |
@@ -25,17 +24,6 @@ export { | |||
25 | 24 | ||
26 | // --------------------------------------------------------------------------- | 25 | // --------------------------------------------------------------------------- |
27 | 26 | ||
28 | async function rateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
29 | const options = { | ||
30 | arguments: [ req, res ], | ||
31 | errorMessage: 'Cannot update the user video rate.' | ||
32 | } | ||
33 | |||
34 | await retryTransactionWrapper(rateVideo, options) | ||
35 | |||
36 | return res.type('json').status(204).end() | ||
37 | } | ||
38 | |||
39 | async function rateVideo (req: express.Request, res: express.Response) { | 27 | async function rateVideo (req: express.Request, res: express.Response) { |
40 | const body: UserVideoRateUpdate = req.body | 28 | const body: UserVideoRateUpdate = req.body |
41 | const rateType = body.rating | 29 | const rateType = body.rating |
@@ -87,4 +75,6 @@ async function rateVideo (req: express.Request, res: express.Response) { | |||
87 | }) | 75 | }) |
88 | 76 | ||
89 | logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name) | 77 | logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name) |
78 | |||
79 | return res.type('json').status(204).end() | ||
90 | } | 80 | } |