aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-31 15:09:34 +0200
committerChocobozzz <me@florianbigard.com>2018-07-31 15:09:34 +0200
commitcf7a61b5a2b68fd966c4a355e37e84b048ed296b (patch)
tree4f4867344fe6856cb4f6b18856867c6e34171ea2 /server/middlewares/validators/videos.ts
parentc487d3033cad9c5e0f85ae49ed3d2a7b6c2711d8 (diff)
downloadPeerTube-cf7a61b5a2b68fd966c4a355e37e84b048ed296b.tar.gz
PeerTube-cf7a61b5a2b68fd966c4a355e37e84b048ed296b.tar.zst
PeerTube-cf7a61b5a2b68fd966c4a355e37e84b048ed296b.zip
Cleanup req files on bad request
Diffstat (limited to 'server/middlewares/validators/videos.ts')
-rw-r--r--server/middlewares/validators/videos.ts22
1 files changed, 12 insertions, 10 deletions
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts
index d9af2aa0a..9357c1e39 100644
--- a/server/middlewares/validators/videos.ts
+++ b/server/middlewares/validators/videos.ts
@@ -35,6 +35,7 @@ import { CONSTRAINTS_FIELDS } from '../../initializers'
35import { VideoShareModel } from '../../models/video/video-share' 35import { VideoShareModel } from '../../models/video/video-share'
36import { authenticate } from '../oauth' 36import { authenticate } from '../oauth'
37import { areValidationErrors } from './utils' 37import { areValidationErrors } from './utils'
38import { cleanUpReqFiles } from '../../helpers/utils'
38 39
39const videosAddValidator = getCommonVideoAttributes().concat([ 40const videosAddValidator = getCommonVideoAttributes().concat([
40 body('videofile') 41 body('videofile')
@@ -50,13 +51,13 @@ const videosAddValidator = getCommonVideoAttributes().concat([
50 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 51 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
51 logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) 52 logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
52 53
53 if (areValidationErrors(req, res)) return 54 if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
54 if (areErrorsInScheduleUpdate(req, res)) return 55 if (areErrorsInScheduleUpdate(req, res)) return cleanUpReqFiles(req)
55 56
56 const videoFile: Express.Multer.File = req.files['videofile'][0] 57 const videoFile: Express.Multer.File = req.files['videofile'][0]
57 const user = res.locals.oauth.token.User 58 const user = res.locals.oauth.token.User
58 59
59 if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return 60 if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
60 61
61 const isAble = await user.isAbleToUploadVideo(videoFile) 62 const isAble = await user.isAbleToUploadVideo(videoFile)
62 if (isAble === false) { 63 if (isAble === false) {
@@ -64,7 +65,7 @@ const videosAddValidator = getCommonVideoAttributes().concat([
64 .json({ error: 'The user video quota is exceeded with this video.' }) 65 .json({ error: 'The user video quota is exceeded with this video.' })
65 .end() 66 .end()
66 67
67 return 68 return cleanUpReqFiles(req)
68 } 69 }
69 70
70 let duration: number 71 let duration: number
@@ -77,7 +78,7 @@ const videosAddValidator = getCommonVideoAttributes().concat([
77 .json({ error: 'Invalid input file.' }) 78 .json({ error: 'Invalid input file.' })
78 .end() 79 .end()
79 80
80 return 81 return cleanUpReqFiles(req)
81 } 82 }
82 83
83 videoFile['duration'] = duration 84 videoFile['duration'] = duration
@@ -99,23 +100,24 @@ const videosUpdateValidator = getCommonVideoAttributes().concat([
99 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 100 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
100 logger.debug('Checking videosUpdate parameters', { parameters: req.body }) 101 logger.debug('Checking videosUpdate parameters', { parameters: req.body })
101 102
102 if (areValidationErrors(req, res)) return 103 if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
103 if (areErrorsInScheduleUpdate(req, res)) return 104 if (areErrorsInScheduleUpdate(req, res)) return cleanUpReqFiles(req)
104 if (!await isVideoExist(req.params.id, res)) return 105 if (!await isVideoExist(req.params.id, res)) return cleanUpReqFiles(req)
105 106
106 const video = res.locals.video 107 const video = res.locals.video
107 108
108 // Check if the user who did the request is able to update the video 109 // Check if the user who did the request is able to update the video
109 const user = res.locals.oauth.token.User 110 const user = res.locals.oauth.token.User
110 if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return 111 if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return cleanUpReqFiles(req)
111 112
112 if (video.privacy !== VideoPrivacy.PRIVATE && req.body.privacy === VideoPrivacy.PRIVATE) { 113 if (video.privacy !== VideoPrivacy.PRIVATE && req.body.privacy === VideoPrivacy.PRIVATE) {
114 cleanUpReqFiles(req)
113 return res.status(409) 115 return res.status(409)
114 .json({ error: 'Cannot set "private" a video that was not private.' }) 116 .json({ error: 'Cannot set "private" a video that was not private.' })
115 .end() 117 .end()
116 } 118 }
117 119
118 if (req.body.channelId && !await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return 120 if (req.body.channelId && !await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
119 121
120 return next() 122 return next()
121 } 123 }