diff options
Diffstat (limited to 'server/middlewares/validators/videos')
3 files changed, 32 insertions, 17 deletions
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' | |||
3 | import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc' | 3 | import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc' |
4 | import { logger } from '@server/helpers/logger' | 4 | import { logger } from '@server/helpers/logger' |
5 | import { CONFIG } from '@server/initializers/config' | 5 | import { CONFIG } from '@server/initializers/config' |
6 | import { VideoChannelModel } from '@server/models/video/video-channel' | ||
7 | import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync' | 6 | import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync' |
8 | import { HttpStatusCode, VideoChannelSyncCreate } from '@shared/models' | 7 | import { HttpStatusCode, VideoChannelSyncCreate } from '@shared/models' |
9 | import { areValidationErrors, doesVideoChannelIdExist } from '../shared' | 8 | import { areValidationErrors, doesVideoChannelIdExist } from '../shared' |
9 | import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs' | ||
10 | 10 | ||
11 | export const ensureSyncIsEnabled = (req: express.Request, res: express.Response, next: express.NextFunction) => { | 11 | export 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' | |||
3 | import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc' | 3 | import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc' |
4 | import { CONFIG } from '@server/initializers/config' | 4 | import { CONFIG } from '@server/initializers/config' |
5 | import { MChannelAccountDefault } from '@server/types/models' | 5 | import { MChannelAccountDefault } from '@server/types/models' |
6 | import { VideosImportInChannelCreate } from '@shared/models' | ||
6 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | 7 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
7 | import { isBooleanValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' | 8 | import { isBooleanValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' |
8 | import { | 9 | import { |
9 | isVideoChannelDescriptionValid, | 10 | isVideoChannelDescriptionValid, |
10 | isVideoChannelDisplayNameValid, | 11 | isVideoChannelDisplayNameValid, |
@@ -15,6 +16,7 @@ import { logger } from '../../../helpers/logger' | |||
15 | import { ActorModel } from '../../../models/actor/actor' | 16 | import { ActorModel } from '../../../models/actor/actor' |
16 | import { VideoChannelModel } from '../../../models/video/video-channel' | 17 | import { VideoChannelModel } from '../../../models/video/video-channel' |
17 | import { areValidationErrors, checkUserQuota, doesVideoChannelNameWithHostExist } from '../shared' | 18 | import { areValidationErrors, checkUserQuota, doesVideoChannelNameWithHostExist } from '../shared' |
19 | import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs' | ||
18 | 20 | ||
19 | export const videoChannelsAddValidator = [ | 21 | export 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 = [ | |||
145 | export const videoChannelImportVideosValidator = [ | 147 | export 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 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { body, param } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { isResolvingToUnicastOnly } from '@server/helpers/dns' | 3 | import { isResolvingToUnicastOnly } from '@server/helpers/dns' |
4 | import { isPreImportVideoAccepted } from '@server/lib/moderation' | 4 | import { isPreImportVideoAccepted } from '@server/lib/moderation' |
5 | import { Hooks } from '@server/lib/plugins/hooks' | 5 | import { Hooks } from '@server/lib/plugins/hooks' |
@@ -92,6 +92,20 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | |||
92 | } | 92 | } |
93 | ]) | 93 | ]) |
94 | 94 | ||
95 | const 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 | |||
95 | const videoImportDeleteValidator = [ | 109 | const 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 = [ | |||
143 | export { | 157 | export { |
144 | videoImportAddValidator, | 158 | videoImportAddValidator, |
145 | videoImportCancelValidator, | 159 | videoImportCancelValidator, |
146 | videoImportDeleteValidator | 160 | videoImportDeleteValidator, |
161 | getMyVideoImportsValidator | ||
147 | } | 162 | } |
148 | 163 | ||
149 | // --------------------------------------------------------------------------- | 164 | // --------------------------------------------------------------------------- |