diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/videos/video-imports.ts | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index 5dc5db533..e3d900a9e 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts | |||
@@ -1,15 +1,18 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator' | 2 | import { body } from 'express-validator' |
3 | import { isPreImportVideoAccepted } from '@server/lib/moderation' | ||
4 | import { Hooks } from '@server/lib/plugins/hooks' | ||
5 | import { VideoImportCreate } from '@shared/models/videos/import/video-import-create.model' | ||
3 | import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' | 6 | import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' |
4 | import { logger } from '../../../helpers/logger' | ||
5 | import { areValidationErrors } from '../utils' | ||
6 | import { getCommonVideoEditAttributes } from './videos' | ||
7 | import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' | 7 | import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' |
8 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | ||
9 | import { isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' | 8 | import { isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' |
9 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | ||
10 | import { logger } from '../../../helpers/logger' | ||
11 | import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares' | ||
10 | import { CONFIG } from '../../../initializers/config' | 12 | import { CONFIG } from '../../../initializers/config' |
11 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 13 | import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' |
12 | import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares' | 14 | import { areValidationErrors } from '../utils' |
15 | import { getCommonVideoEditAttributes } from './videos' | ||
13 | 16 | ||
14 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | 17 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ |
15 | body('channelId') | 18 | body('channelId') |
@@ -64,6 +67,8 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | |||
64 | .end() | 67 | .end() |
65 | } | 68 | } |
66 | 69 | ||
70 | if (!await isImportAccepted(req, res)) return cleanUpReqFiles(req) | ||
71 | |||
67 | return next() | 72 | return next() |
68 | } | 73 | } |
69 | ]) | 74 | ]) |
@@ -75,3 +80,31 @@ export { | |||
75 | } | 80 | } |
76 | 81 | ||
77 | // --------------------------------------------------------------------------- | 82 | // --------------------------------------------------------------------------- |
83 | |||
84 | async function isImportAccepted (req: express.Request, res: express.Response) { | ||
85 | const body: VideoImportCreate = req.body | ||
86 | const hookName = body.targetUrl | ||
87 | ? 'filter:api.video.pre-import-url.accept.result' | ||
88 | : 'filter:api.video.pre-import-torrent.accept.result' | ||
89 | |||
90 | // Check we accept this video | ||
91 | const acceptParameters = { | ||
92 | videoImportBody: body, | ||
93 | user: res.locals.oauth.token.User | ||
94 | } | ||
95 | const acceptedResult = await Hooks.wrapFun( | ||
96 | isPreImportVideoAccepted, | ||
97 | acceptParameters, | ||
98 | hookName | ||
99 | ) | ||
100 | |||
101 | if (!acceptedResult || acceptedResult.accepted !== true) { | ||
102 | logger.info('Refused to import video.', { acceptedResult, acceptParameters }) | ||
103 | res.status(403) | ||
104 | .json({ error: acceptedResult.errorMessage || 'Refused to import video' }) | ||
105 | |||
106 | return false | ||
107 | } | ||
108 | |||
109 | return true | ||
110 | } | ||