PeerTube/server/core/controllers/api/videos/rate.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-08-27 14:32:44 +02:00
import express from 'express'
import { HttpStatusCode, UserVideoRateUpdate } from '@peertube/peertube-models'
import { logger } from '../../../helpers/logger.js'
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoUpdateRateValidator } from '../../../middlewares/index.js'
2024-02-12 10:47:52 +01:00
import { userRateVideo } from '@server/lib/rate.js'
2017-05-15 22:22:03 +02:00
const rateVideoRouter = express.Router()
rateVideoRouter.put('/:id/rate',
authenticate,
2018-11-14 15:01:28 +01:00
asyncMiddleware(videoUpdateRateValidator),
2018-06-13 14:27:40 +02:00
asyncRetryTransactionMiddleware(rateVideo)
2017-05-05 16:53:35 +02:00
)
// ---------------------------------------------------------------------------
2017-05-15 22:22:03 +02:00
export {
rateVideoRouter
}
2017-05-05 16:53:35 +02:00
// ---------------------------------------------------------------------------
2017-10-25 11:55:06 +02:00
async function rateVideo (req: express.Request, res: express.Response) {
2024-02-12 10:47:52 +01:00
const user = res.locals.oauth.token.User
const video = res.locals.videoAll
2017-05-05 16:53:35 +02:00
2024-02-12 10:47:52 +01:00
await userRateVideo({
account: user.Account,
rateType: (req.body as UserVideoRateUpdate).rating,
video
})
2018-06-13 14:27:40 +02:00
2024-02-12 10:47:52 +01:00
logger.info('Account video rate for video %s of account %s updated.', video.name, user.username)
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
2017-05-05 16:53:35 +02:00
}