aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/users.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-11 16:01:56 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-11 16:01:56 +0200
commit0a6658fdcbd779ada8f3758048c326e997902d5a (patch)
tree5de40bf901db0299011104b1344783637b964eb0 /server/middlewares/validators/users.ts
parente6d4b0ff2404dcf0b3a755c3fcc415ffeb6e754d (diff)
downloadPeerTube-0a6658fdcbd779ada8f3758048c326e997902d5a.tar.gz
PeerTube-0a6658fdcbd779ada8f3758048c326e997902d5a.tar.zst
PeerTube-0a6658fdcbd779ada8f3758048c326e997902d5a.zip
Use global uuid instead of remoteId for videos
Diffstat (limited to 'server/middlewares/validators/users.ts')
-rw-r--r--server/middlewares/validators/users.ts15
1 files changed, 13 insertions, 2 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 9db4fff77..90a46752c 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -1,9 +1,12 @@
1import 'express-validator' 1import 'express-validator'
2import * as express from 'express' 2import * as express from 'express'
3import * as Promise from 'bluebird'
4import * as validator from 'validator'
3 5
4import { database as db } from '../../initializers/database' 6import { database as db } from '../../initializers/database'
5import { checkErrors } from './utils' 7import { checkErrors } from './utils'
6import { logger } from '../../helpers' 8import { logger } from '../../helpers'
9import { VideoInstance } from '../../models'
7 10
8function usersAddValidator (req: express.Request, res: express.Response, next: express.NextFunction) { 11function usersAddValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
9 req.checkBody('username', 'Should have a valid username').isUserUsernameValid() 12 req.checkBody('username', 'Should have a valid username').isUserUsernameValid()
@@ -59,12 +62,20 @@ function usersUpdateValidator (req: express.Request, res: express.Response, next
59} 62}
60 63
61function usersVideoRatingValidator (req: express.Request, res: express.Response, next: express.NextFunction) { 64function usersVideoRatingValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
62 req.checkParams('videoId', 'Should have a valid video id').notEmpty().isUUID(4) 65 req.checkParams('videoId', 'Should have a valid video id').notEmpty().isVideoIdOrUUIDValid()
63 66
64 logger.debug('Checking usersVideoRating parameters', { parameters: req.params }) 67 logger.debug('Checking usersVideoRating parameters', { parameters: req.params })
65 68
66 checkErrors(req, res, function () { 69 checkErrors(req, res, function () {
67 db.Video.load(req.params.videoId) 70 let videoPromise: Promise<VideoInstance>
71
72 if (validator.isUUID(req.params.videoId)) {
73 videoPromise = db.Video.loadByUUID(req.params.videoId)
74 } else {
75 videoPromise = db.Video.load(req.params.videoId)
76 }
77
78 videoPromise
68 .then(video => { 79 .then(video => {
69 if (!video) return res.status(404).send('Video not found') 80 if (!video) return res.status(404).send('Video not found')
70 81