1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Cleanup req files on bad request

This commit is contained in:
Chocobozzz 2018-07-31 15:09:34 +02:00
parent c487d3033c
commit cf7a61b5a2
No known key found for this signature in database
GPG key ID: 583A612D890159BE
9 changed files with 50 additions and 22 deletions

View file

@ -7,6 +7,7 @@ import { CONSTRAINTS_FIELDS } from '../../initializers'
import { UserRight } from '../../../shared'
import { logger } from '../../helpers/logger'
import { isVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions'
import { cleanUpReqFiles } from '../../helpers/utils'
const addVideoCaptionValidator = [
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'),
@ -20,12 +21,12 @@ const addVideoCaptionValidator = [
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking addVideoCaption parameters', { parameters: req.body })
if (areValidationErrors(req, res)) return
if (!await isVideoExist(req.params.videoId, res)) return
if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
if (!await isVideoExist(req.params.videoId, res)) return cleanUpReqFiles(req)
// Check if the user who did the request is able to update the video
const user = res.locals.oauth.token.User
if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return
if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return cleanUpReqFiles(req)
return next()
}