aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/validators/shared/index.ts1
-rw-r--r--server/middlewares/validators/shared/video-channel-syncs.ts24
-rw-r--r--server/middlewares/validators/videos/video-channel-sync.ts16
-rw-r--r--server/middlewares/validators/videos/video-channels.ts14
-rw-r--r--server/middlewares/validators/videos/video-imports.ts19
5 files changed, 57 insertions, 17 deletions
diff --git a/server/middlewares/validators/shared/index.ts b/server/middlewares/validators/shared/index.ts
index fa89d05f2..bbd03b248 100644
--- a/server/middlewares/validators/shared/index.ts
+++ b/server/middlewares/validators/shared/index.ts
@@ -4,6 +4,7 @@ export * from './utils'
4export * from './video-blacklists' 4export * from './video-blacklists'
5export * from './video-captions' 5export * from './video-captions'
6export * from './video-channels' 6export * from './video-channels'
7export * from './video-channel-syncs'
7export * from './video-comments' 8export * from './video-comments'
8export * from './video-imports' 9export * from './video-imports'
9export * from './video-ownerships' 10export * from './video-ownerships'
diff --git a/server/middlewares/validators/shared/video-channel-syncs.ts b/server/middlewares/validators/shared/video-channel-syncs.ts
new file mode 100644
index 000000000..a6e51eb97
--- /dev/null
+++ b/server/middlewares/validators/shared/video-channel-syncs.ts
@@ -0,0 +1,24 @@
1import express from 'express'
2import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'
3import { HttpStatusCode } from '@shared/models'
4
5async function doesVideoChannelSyncIdExist (id: number, res: express.Response) {
6 const sync = await VideoChannelSyncModel.loadWithChannel(+id)
7
8 if (!sync) {
9 res.fail({
10 status: HttpStatusCode.NOT_FOUND_404,
11 message: 'Video channel sync not found'
12 })
13 return false
14 }
15
16 res.locals.videoChannelSync = sync
17 return true
18}
19
20// ---------------------------------------------------------------------------
21
22export {
23 doesVideoChannelSyncIdExist
24}
diff --git a/server/middlewares/validators/videos/video-channel-sync.ts b/server/middlewares/validators/videos/video-channel-sync.ts
index b18498243..081f09bba 100644
--- a/server/middlewares/validators/videos/video-channel-sync.ts
+++ b/server/middlewares/validators/videos/video-channel-sync.ts
@@ -3,10 +3,10 @@ import { body, param } from 'express-validator'
3import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc' 3import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
4import { logger } from '@server/helpers/logger' 4import { logger } from '@server/helpers/logger'
5import { CONFIG } from '@server/initializers/config' 5import { CONFIG } from '@server/initializers/config'
6import { VideoChannelModel } from '@server/models/video/video-channel'
7import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync' 6import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'
8import { HttpStatusCode, VideoChannelSyncCreate } from '@shared/models' 7import { HttpStatusCode, VideoChannelSyncCreate } from '@shared/models'
9import { areValidationErrors, doesVideoChannelIdExist } from '../shared' 8import { areValidationErrors, doesVideoChannelIdExist } from '../shared'
9import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs'
10 10
11export const ensureSyncIsEnabled = (req: express.Request, res: express.Response, next: express.NextFunction) => { 11export const ensureSyncIsEnabled = (req: express.Request, res: express.Response, next: express.NextFunction) => {
12 if (!CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED) { 12 if (!CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED) {
@@ -48,18 +48,8 @@ export const ensureSyncExists = [
48 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 48 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
49 if (areValidationErrors(req, res)) return 49 if (areValidationErrors(req, res)) return
50 50
51 const syncId = parseInt(req.params.id, 10) 51 if (!await doesVideoChannelSyncIdExist(+req.params.id, res)) return
52 const sync = await VideoChannelSyncModel.loadWithChannel(syncId) 52 if (!await doesVideoChannelIdExist(res.locals.videoChannelSync.videoChannelId, res)) return
53
54 if (!sync) {
55 return res.fail({
56 status: HttpStatusCode.NOT_FOUND_404,
57 message: 'Synchronization not found'
58 })
59 }
60
61 res.locals.videoChannelSync = sync
62 res.locals.videoChannel = await VideoChannelModel.loadAndPopulateAccount(sync.videoChannelId)
63 53
64 return next() 54 return next()
65 } 55 }
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts
index 88f8b814d..d53c777fa 100644
--- a/server/middlewares/validators/videos/video-channels.ts
+++ b/server/middlewares/validators/videos/video-channels.ts
@@ -3,8 +3,9 @@ import { body, param, query } from 'express-validator'
3import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc' 3import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
4import { CONFIG } from '@server/initializers/config' 4import { CONFIG } from '@server/initializers/config'
5import { MChannelAccountDefault } from '@server/types/models' 5import { MChannelAccountDefault } from '@server/types/models'
6import { VideosImportInChannelCreate } from '@shared/models'
6import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' 7import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
7import { isBooleanValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' 8import { isBooleanValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc'
8import { 9import {
9 isVideoChannelDescriptionValid, 10 isVideoChannelDescriptionValid,
10 isVideoChannelDisplayNameValid, 11 isVideoChannelDisplayNameValid,
@@ -15,6 +16,7 @@ import { logger } from '../../../helpers/logger'
15import { ActorModel } from '../../../models/actor/actor' 16import { ActorModel } from '../../../models/actor/actor'
16import { VideoChannelModel } from '../../../models/video/video-channel' 17import { VideoChannelModel } from '../../../models/video/video-channel'
17import { areValidationErrors, checkUserQuota, doesVideoChannelNameWithHostExist } from '../shared' 18import { areValidationErrors, checkUserQuota, doesVideoChannelNameWithHostExist } from '../shared'
19import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs'
18 20
19export const videoChannelsAddValidator = [ 21export const videoChannelsAddValidator = [
20 body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), 22 body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'),
@@ -145,11 +147,17 @@ export const videoChannelsListValidator = [
145export const videoChannelImportVideosValidator = [ 147export const videoChannelImportVideosValidator = [
146 body('externalChannelUrl').custom(isUrlValid).withMessage('Should have a valid channel url'), 148 body('externalChannelUrl').custom(isUrlValid).withMessage('Should have a valid channel url'),
147 149
148 (req: express.Request, res: express.Response, next: express.NextFunction) => { 150 body('videoChannelSyncId')
151 .optional()
152 .custom(isIdValid).withMessage('Should have a valid channel sync id'),
153
154 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
149 logger.debug('Checking videoChannelImport parameters', { parameters: req.body }) 155 logger.debug('Checking videoChannelImport parameters', { parameters: req.body })
150 156
151 if (areValidationErrors(req, res)) return 157 if (areValidationErrors(req, res)) return
152 158
159 const body: VideosImportInChannelCreate = req.body
160
153 if (!CONFIG.IMPORT.VIDEOS.HTTP.ENABLED) { 161 if (!CONFIG.IMPORT.VIDEOS.HTTP.ENABLED) {
154 return res.fail({ 162 return res.fail({
155 status: HttpStatusCode.FORBIDDEN_403, 163 status: HttpStatusCode.FORBIDDEN_403,
@@ -157,6 +165,8 @@ export const videoChannelImportVideosValidator = [
157 }) 165 })
158 } 166 }
159 167
168 if (body.videoChannelSyncId && !await doesVideoChannelSyncIdExist(body.videoChannelSyncId, res)) return
169
160 return next() 170 return next()
161 } 171 }
162] 172]
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts
index 9c6d213c4..3115acb21 100644
--- a/server/middlewares/validators/videos/video-imports.ts
+++ b/server/middlewares/validators/videos/video-imports.ts
@@ -1,5 +1,5 @@
1import express from 'express' 1import express from 'express'
2import { body, param } from 'express-validator' 2import { body, param, query } from 'express-validator'
3import { isResolvingToUnicastOnly } from '@server/helpers/dns' 3import { isResolvingToUnicastOnly } from '@server/helpers/dns'
4import { isPreImportVideoAccepted } from '@server/lib/moderation' 4import { isPreImportVideoAccepted } from '@server/lib/moderation'
5import { Hooks } from '@server/lib/plugins/hooks' 5import { Hooks } from '@server/lib/plugins/hooks'
@@ -92,6 +92,20 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([
92 } 92 }
93]) 93])
94 94
95const getMyVideoImportsValidator = [
96 query('videoChannelSyncId')
97 .optional()
98 .custom(isIdValid).withMessage('Should have correct videoChannelSync id'),
99
100 (req: express.Request, res: express.Response, next: express.NextFunction) => {
101 logger.debug('Checking getMyVideoImportsValidator parameters', { parameters: req.params })
102
103 if (areValidationErrors(req, res)) return
104
105 return next()
106 }
107]
108
95const videoImportDeleteValidator = [ 109const videoImportDeleteValidator = [
96 param('id') 110 param('id')
97 .custom(isIdValid).withMessage('Should have correct import id'), 111 .custom(isIdValid).withMessage('Should have correct import id'),
@@ -143,7 +157,8 @@ const videoImportCancelValidator = [
143export { 157export {
144 videoImportAddValidator, 158 videoImportAddValidator,
145 videoImportCancelValidator, 159 videoImportCancelValidator,
146 videoImportDeleteValidator 160 videoImportDeleteValidator,
161 getMyVideoImportsValidator
147} 162}
148 163
149// --------------------------------------------------------------------------- 164// ---------------------------------------------------------------------------