diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-02 16:33:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-06 11:19:16 +0200 |
commit | 299474e8279675adb6c5ce140e7e39c6f3439453 (patch) | |
tree | 32962c4a6878e4f4268e10eb0fbb9db670013ad3 /server/middlewares | |
parent | ce32426be941164d041526e4748b4c83cdc6bf1c (diff) | |
download | PeerTube-299474e8279675adb6c5ce140e7e39c6f3439453.tar.gz PeerTube-299474e8279675adb6c5ce140e7e39c6f3439453.tar.zst PeerTube-299474e8279675adb6c5ce140e7e39c6f3439453.zip |
Add ability to remove a video import
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/video-imports.ts | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/server/middlewares/validators/video-imports.ts b/server/middlewares/validators/video-imports.ts index 0ba759ff0..0dedcf803 100644 --- a/server/middlewares/validators/video-imports.ts +++ b/server/middlewares/validators/video-imports.ts | |||
@@ -4,9 +4,11 @@ import { isIdValid } from '../../helpers/custom-validators/misc' | |||
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
6 | import { getCommonVideoAttributes } from './videos' | 6 | import { getCommonVideoAttributes } from './videos' |
7 | import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' | 7 | import { isVideoImportTargetUrlValid, isVideoImportExist } from '../../helpers/custom-validators/video-imports' |
8 | import { cleanUpReqFiles } from '../../helpers/utils' | 8 | import { cleanUpReqFiles } from '../../helpers/utils' |
9 | import { isVideoChannelOfAccountExist, isVideoNameValid } from '../../helpers/custom-validators/videos' | 9 | import { isVideoChannelOfAccountExist, isVideoNameValid, checkUserCanManageVideo } from '../../helpers/custom-validators/videos' |
10 | import { VideoImportModel } from '../../models/video/video-import' | ||
11 | import { UserRight } from '../../../shared' | ||
10 | 12 | ||
11 | const videoImportAddValidator = getCommonVideoAttributes().concat([ | 13 | const videoImportAddValidator = getCommonVideoAttributes().concat([ |
12 | body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'), | 14 | body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'), |
@@ -32,10 +34,16 @@ const videoImportAddValidator = getCommonVideoAttributes().concat([ | |||
32 | const videoImportDeleteValidator = [ | 34 | const videoImportDeleteValidator = [ |
33 | param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), | 35 | param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), |
34 | 36 | ||
35 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 37 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
36 | logger.debug('Checking videoImportDeleteValidator parameters', { parameters: req.body }) | 38 | logger.debug('Checking videoImportDeleteValidator parameters', { parameters: req.body }) |
37 | 39 | ||
38 | if (areValidationErrors(req, res)) return | 40 | if (areValidationErrors(req, res)) return |
41 | if (!await isVideoImportExist(req.params.id, res)) return | ||
42 | |||
43 | const user = res.locals.oauth.token.User | ||
44 | const videoImport: VideoImportModel = res.locals.videoImport | ||
45 | |||
46 | if (!await checkUserCanManageVideo(user, videoImport.Video, UserRight.UPDATE_ANY_VIDEO, res)) return | ||
39 | 47 | ||
40 | return next() | 48 | return next() |
41 | } | 49 | } |