aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos.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/videos.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/videos.ts')
-rw-r--r--server/middlewares/validators/videos.ts24
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 @@
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 { CONSTRAINTS_FIELDS, SEARCHABLE_COLUMNS } from '../../initializers' 8import { CONSTRAINTS_FIELDS, SEARCHABLE_COLUMNS } from '../../initializers'
7import { logger, isVideoDurationValid } from '../../helpers' 9import { logger, isVideoDurationValid } from '../../helpers'
10import { VideoInstance } from '../../models'
8 11
9function videosAddValidator (req: express.Request, res: express.Response, next: express.NextFunction) { 12function 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
42function videosUpdateValidator (req: express.Request, res: express.Response, next: express.NextFunction) { 45function 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
70function videosGetValidator (req: express.Request, res: express.Response, next: express.NextFunction) { 73function 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
80function videosRemoveValidator (req: express.Request, res: express.Response, next: express.NextFunction) { 83function 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
107function videoAbuseReportValidator (req: express.Request, res: express.Response, next: express.NextFunction) { 110function 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
118function videoRateValidator (req: express.Request, res: express.Response, next: express.NextFunction) { 121function 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
129function videosBlacklistValidator (req: express.Request, res: express.Response, next: express.NextFunction) { 132function 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
159function checkVideoExists (id: string, res: express.Response, callback: () => void) { 162function 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