diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-11 16:01:56 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-11 16:01:56 +0200 |
commit | 0a6658fdcbd779ada8f3758048c326e997902d5a (patch) | |
tree | 5de40bf901db0299011104b1344783637b964eb0 /server/middlewares/validators/users.ts | |
parent | e6d4b0ff2404dcf0b3a755c3fcc415ffeb6e754d (diff) | |
download | PeerTube-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.ts | 15 |
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 @@ | |||
1 | import 'express-validator' | 1 | import 'express-validator' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import * as Promise from 'bluebird' | ||
4 | import * as validator from 'validator' | ||
3 | 5 | ||
4 | import { database as db } from '../../initializers/database' | 6 | import { database as db } from '../../initializers/database' |
5 | import { checkErrors } from './utils' | 7 | import { checkErrors } from './utils' |
6 | import { logger } from '../../helpers' | 8 | import { logger } from '../../helpers' |
9 | import { VideoInstance } from '../../models' | ||
7 | 10 | ||
8 | function usersAddValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | 11 | function 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 | ||
61 | function usersVideoRatingValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | 64 | function 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 | ||