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/videos.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/videos.ts')
-rw-r--r-- | server/middlewares/validators/videos.ts | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index 013466487..0a88e064e 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts | |||
@@ -1,10 +1,13 @@ | |||
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 { CONSTRAINTS_FIELDS, SEARCHABLE_COLUMNS } from '../../initializers' | 8 | import { CONSTRAINTS_FIELDS, SEARCHABLE_COLUMNS } from '../../initializers' |
7 | import { logger, isVideoDurationValid } from '../../helpers' | 9 | import { logger, isVideoDurationValid } from '../../helpers' |
10 | import { VideoInstance } from '../../models' | ||
8 | 11 | ||
9 | function videosAddValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | 12 | function videosAddValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
10 | // FIXME: Don't write an error message, it seems there is a bug with express-validator | 13 | // FIXME: Don't write an error message, it seems there is a bug with express-validator |
@@ -40,7 +43,7 @@ function videosAddValidator (req: express.Request, res: express.Response, next: | |||
40 | } | 43 | } |
41 | 44 | ||
42 | function videosUpdateValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | 45 | function videosUpdateValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
43 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 46 | req.checkParams('id', 'Should have a valid id').notEmpty().isVideoIdOrUUIDValid() |
44 | req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid() | 47 | req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid() |
45 | req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid() | 48 | req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid() |
46 | req.checkBody('licence', 'Should have a valid licence').optional().isVideoLicenceValid() | 49 | req.checkBody('licence', 'Should have a valid licence').optional().isVideoLicenceValid() |
@@ -68,7 +71,7 @@ function videosUpdateValidator (req: express.Request, res: express.Response, nex | |||
68 | } | 71 | } |
69 | 72 | ||
70 | function videosGetValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | 73 | function videosGetValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
71 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 74 | req.checkParams('id', 'Should have a valid id').notEmpty().isVideoIdOrUUIDValid() |
72 | 75 | ||
73 | logger.debug('Checking videosGet parameters', { parameters: req.params }) | 76 | logger.debug('Checking videosGet parameters', { parameters: req.params }) |
74 | 77 | ||
@@ -78,7 +81,7 @@ function videosGetValidator (req: express.Request, res: express.Response, next: | |||
78 | } | 81 | } |
79 | 82 | ||
80 | function videosRemoveValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | 83 | function videosRemoveValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
81 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 84 | req.checkParams('id', 'Should have a valid id').notEmpty().isVideoIdOrUUIDValid() |
82 | 85 | ||
83 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) | 86 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) |
84 | 87 | ||
@@ -105,7 +108,7 @@ function videosSearchValidator (req: express.Request, res: express.Response, nex | |||
105 | } | 108 | } |
106 | 109 | ||
107 | function videoAbuseReportValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | 110 | function videoAbuseReportValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
108 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 111 | req.checkParams('id', 'Should have a valid id').notEmpty().isVideoIdOrUUIDValid() |
109 | req.checkBody('reason', 'Should have a valid reason').isVideoAbuseReasonValid() | 112 | req.checkBody('reason', 'Should have a valid reason').isVideoAbuseReasonValid() |
110 | 113 | ||
111 | logger.debug('Checking videoAbuseReport parameters', { parameters: req.body }) | 114 | logger.debug('Checking videoAbuseReport parameters', { parameters: req.body }) |
@@ -116,7 +119,7 @@ function videoAbuseReportValidator (req: express.Request, res: express.Response, | |||
116 | } | 119 | } |
117 | 120 | ||
118 | function videoRateValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | 121 | function videoRateValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
119 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 122 | req.checkParams('id', 'Should have a valid id').notEmpty().isVideoIdOrUUIDValid() |
120 | req.checkBody('rating', 'Should have a valid rate type').isVideoRatingTypeValid() | 123 | req.checkBody('rating', 'Should have a valid rate type').isVideoRatingTypeValid() |
121 | 124 | ||
122 | logger.debug('Checking videoRate parameters', { parameters: req.body }) | 125 | logger.debug('Checking videoRate parameters', { parameters: req.body }) |
@@ -127,7 +130,7 @@ function videoRateValidator (req: express.Request, res: express.Response, next: | |||
127 | } | 130 | } |
128 | 131 | ||
129 | function videosBlacklistValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | 132 | function videosBlacklistValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
130 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 133 | req.checkParams('id', 'Should have a valid id').notEmpty().isVideoIdOrUUIDValid() |
131 | 134 | ||
132 | logger.debug('Checking videosBlacklist parameters', { parameters: req.params }) | 135 | logger.debug('Checking videosBlacklist parameters', { parameters: req.params }) |
133 | 136 | ||
@@ -157,7 +160,14 @@ export { | |||
157 | // --------------------------------------------------------------------------- | 160 | // --------------------------------------------------------------------------- |
158 | 161 | ||
159 | function checkVideoExists (id: string, res: express.Response, callback: () => void) { | 162 | function checkVideoExists (id: string, res: express.Response, callback: () => void) { |
160 | db.Video.loadAndPopulateAuthorAndPodAndTags(id).then(video => { | 163 | let promise: Promise<VideoInstance> |
164 | if (validator.isInt(id)) { | ||
165 | promise = db.Video.loadAndPopulateAuthorAndPodAndTags(+id) | ||
166 | } else { // UUID | ||
167 | promise = db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(id) | ||
168 | } | ||
169 | |||
170 | promise.then(video => { | ||
161 | if (!video) return res.status(404).send('Video not found') | 171 | if (!video) return res.status(404).send('Video not found') |
162 | 172 | ||
163 | res.locals.video = video | 173 | res.locals.video = video |