aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-24 19:41:09 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-26 09:11:38 +0200
commit72c7248b6fdcdb2175e726ff51b42e7555f2bd84 (patch)
tree1bfdee99dbe2392cc997edba8e314e2a8a401c72 /server/middlewares/validators/videos.ts
parent8113a93a0d9f31aa9e23702bbc31b8a76275ae22 (diff)
downloadPeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.tar.gz
PeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.tar.zst
PeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.zip
Add video channels
Diffstat (limited to 'server/middlewares/validators/videos.ts')
-rw-r--r--server/middlewares/validators/videos.ts33
1 files changed, 24 insertions, 9 deletions
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts
index 3f881e1b5..8a9b383b8 100644
--- a/server/middlewares/validators/videos.ts
+++ b/server/middlewares/validators/videos.ts
@@ -15,11 +15,12 @@ import {
15 isVideoLanguageValid, 15 isVideoLanguageValid,
16 isVideoTagsValid, 16 isVideoTagsValid,
17 isVideoNSFWValid, 17 isVideoNSFWValid,
18 isVideoIdOrUUIDValid, 18 isIdOrUUIDValid,
19 isVideoAbuseReasonValid, 19 isVideoAbuseReasonValid,
20 isVideoRatingTypeValid, 20 isVideoRatingTypeValid,
21 getDurationFromVideoFile, 21 getDurationFromVideoFile,
22 checkVideoExists 22 checkVideoExists,
23 isIdValid
23} from '../../helpers' 24} from '../../helpers'
24 25
25const videosAddValidator = [ 26const videosAddValidator = [
@@ -33,6 +34,7 @@ const videosAddValidator = [
33 body('language').optional().custom(isVideoLanguageValid).withMessage('Should have a valid language'), 34 body('language').optional().custom(isVideoLanguageValid).withMessage('Should have a valid language'),
34 body('nsfw').custom(isVideoNSFWValid).withMessage('Should have a valid NSFW attribute'), 35 body('nsfw').custom(isVideoNSFWValid).withMessage('Should have a valid NSFW attribute'),
35 body('description').custom(isVideoDescriptionValid).withMessage('Should have a valid description'), 36 body('description').custom(isVideoDescriptionValid).withMessage('Should have a valid description'),
37 body('channelId').custom(isIdValid).withMessage('Should have correct video channel id'),
36 body('tags').optional().custom(isVideoTagsValid).withMessage('Should have correct tags'), 38 body('tags').optional().custom(isVideoTagsValid).withMessage('Should have correct tags'),
37 39
38 (req: express.Request, res: express.Response, next: express.NextFunction) => { 40 (req: express.Request, res: express.Response, next: express.NextFunction) => {
@@ -42,7 +44,20 @@ const videosAddValidator = [
42 const videoFile: Express.Multer.File = req.files['videofile'][0] 44 const videoFile: Express.Multer.File = req.files['videofile'][0]
43 const user = res.locals.oauth.token.User 45 const user = res.locals.oauth.token.User
44 46
45 user.isAbleToUploadVideo(videoFile) 47 return db.VideoChannel.loadByIdAndAuthor(req.body.channelId, user.Author.id)
48 .then(videoChannel => {
49 if (!videoChannel) {
50 res.status(400)
51 .json({ error: 'Unknown video video channel for this author.' })
52 .end()
53
54 return undefined
55 }
56
57 res.locals.videoChannel = videoChannel
58
59 return user.isAbleToUploadVideo(videoFile)
60 })
46 .then(isAble => { 61 .then(isAble => {
47 if (isAble === false) { 62 if (isAble === false) {
48 res.status(403) 63 res.status(403)
@@ -88,7 +103,7 @@ const videosAddValidator = [
88] 103]
89 104
90const videosUpdateValidator = [ 105const videosUpdateValidator = [
91 param('id').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 106 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
92 body('name').optional().custom(isVideoNameValid).withMessage('Should have a valid name'), 107 body('name').optional().custom(isVideoNameValid).withMessage('Should have a valid name'),
93 body('category').optional().custom(isVideoCategoryValid).withMessage('Should have a valid category'), 108 body('category').optional().custom(isVideoCategoryValid).withMessage('Should have a valid category'),
94 body('licence').optional().custom(isVideoLicenceValid).withMessage('Should have a valid licence'), 109 body('licence').optional().custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
@@ -109,7 +124,7 @@ const videosUpdateValidator = [
109 .end() 124 .end()
110 } 125 }
111 126
112 if (res.locals.video.Author.userId !== res.locals.oauth.token.User.id) { 127 if (res.locals.video.VideoChannel.Author.userId !== res.locals.oauth.token.User.id) {
113 return res.status(403) 128 return res.status(403)
114 .json({ error: 'Cannot update video of another user' }) 129 .json({ error: 'Cannot update video of another user' })
115 .end() 130 .end()
@@ -122,7 +137,7 @@ const videosUpdateValidator = [
122] 137]
123 138
124const videosGetValidator = [ 139const videosGetValidator = [
125 param('id').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 140 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
126 141
127 (req: express.Request, res: express.Response, next: express.NextFunction) => { 142 (req: express.Request, res: express.Response, next: express.NextFunction) => {
128 logger.debug('Checking videosGet parameters', { parameters: req.params }) 143 logger.debug('Checking videosGet parameters', { parameters: req.params })
@@ -134,7 +149,7 @@ const videosGetValidator = [
134] 149]
135 150
136const videosRemoveValidator = [ 151const videosRemoveValidator = [
137 param('id').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 152 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
138 153
139 (req: express.Request, res: express.Response, next: express.NextFunction) => { 154 (req: express.Request, res: express.Response, next: express.NextFunction) => {
140 logger.debug('Checking videosRemove parameters', { parameters: req.params }) 155 logger.debug('Checking videosRemove parameters', { parameters: req.params })
@@ -162,7 +177,7 @@ const videosSearchValidator = [
162] 177]
163 178
164const videoAbuseReportValidator = [ 179const videoAbuseReportValidator = [
165 param('id').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 180 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
166 body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'), 181 body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'),
167 182
168 (req: express.Request, res: express.Response, next: express.NextFunction) => { 183 (req: express.Request, res: express.Response, next: express.NextFunction) => {
@@ -175,7 +190,7 @@ const videoAbuseReportValidator = [
175] 190]
176 191
177const videoRateValidator = [ 192const videoRateValidator = [
178 param('id').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 193 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
179 body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'), 194 body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'),
180 195
181 (req: express.Request, res: express.Response, next: express.NextFunction) => { 196 (req: express.Request, res: express.Response, next: express.NextFunction) => {