2021-08-27 07:32:44 -05:00
|
|
|
import express from 'express'
|
2023-07-31 07:34:36 -05:00
|
|
|
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 03:47:52 -06:00
|
|
|
import { userRateVideo } from '@server/lib/rate.js'
|
2017-05-15 15:22:03 -05:00
|
|
|
|
|
|
|
const rateVideoRouter = express.Router()
|
|
|
|
|
|
|
|
rateVideoRouter.put('/:id/rate',
|
|
|
|
authenticate,
|
2018-11-14 08:01:28 -06:00
|
|
|
asyncMiddleware(videoUpdateRateValidator),
|
2018-06-13 07:27:40 -05:00
|
|
|
asyncRetryTransactionMiddleware(rateVideo)
|
2017-05-05 09:53:35 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 15:22:03 -05:00
|
|
|
export {
|
|
|
|
rateVideoRouter
|
|
|
|
}
|
2017-05-05 09:53:35 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-10-25 04:55:06 -05:00
|
|
|
async function rateVideo (req: express.Request, res: express.Response) {
|
2024-02-12 03:47:52 -06:00
|
|
|
const user = res.locals.oauth.token.User
|
|
|
|
const video = res.locals.videoAll
|
2017-05-05 09:53:35 -05:00
|
|
|
|
2024-02-12 03:47:52 -06:00
|
|
|
await userRateVideo({
|
|
|
|
account: user.Account,
|
|
|
|
rateType: (req.body as UserVideoRateUpdate).rating,
|
|
|
|
video
|
2018-09-20 03:13:13 -05:00
|
|
|
})
|
2018-06-13 07:27:40 -05:00
|
|
|
|
2024-02-12 03:47:52 -06: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 09:53:35 -05:00
|
|
|
}
|