aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/videos/video-imports.ts43
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator' 2import { body } from 'express-validator'
3import { isPreImportVideoAccepted } from '@server/lib/moderation'
4import { Hooks } from '@server/lib/plugins/hooks'
5import { VideoImportCreate } from '@shared/models/videos/import/video-import-create.model'
3import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' 6import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc'
4import { logger } from '../../../helpers/logger'
5import { areValidationErrors } from '../utils'
6import { getCommonVideoEditAttributes } from './videos'
7import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' 7import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports'
8import { cleanUpReqFiles } from '../../../helpers/express-utils'
9import { isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' 8import { isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos'
9import { cleanUpReqFiles } from '../../../helpers/express-utils'
10import { logger } from '../../../helpers/logger'
11import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares'
10import { CONFIG } from '../../../initializers/config' 12import { CONFIG } from '../../../initializers/config'
11import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 13import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
12import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares' 14import { areValidationErrors } from '../utils'
15import { getCommonVideoEditAttributes } from './videos'
13 16
14const videoImportAddValidator = getCommonVideoEditAttributes().concat([ 17const 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
84async 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}