aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos/video-channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/videos/video-channels.ts')
-rw-r--r--server/middlewares/validators/videos/video-channels.ts55
1 files changed, 37 insertions, 18 deletions
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts
index 3bfdebbb1..88f8b814d 100644
--- a/server/middlewares/validators/videos/video-channels.ts
+++ b/server/middlewares/validators/videos/video-channels.ts
@@ -1,5 +1,6 @@
1import express from 'express' 1import express from 'express'
2import { body, param, query } from 'express-validator' 2import { body, param, query } from 'express-validator'
3import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
3import { CONFIG } from '@server/initializers/config' 4import { CONFIG } from '@server/initializers/config'
4import { MChannelAccountDefault } from '@server/types/models' 5import { MChannelAccountDefault } from '@server/types/models'
5import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' 6import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
@@ -13,9 +14,9 @@ import {
13import { logger } from '../../../helpers/logger' 14import { logger } from '../../../helpers/logger'
14import { ActorModel } from '../../../models/actor/actor' 15import { ActorModel } from '../../../models/actor/actor'
15import { VideoChannelModel } from '../../../models/video/video-channel' 16import { VideoChannelModel } from '../../../models/video/video-channel'
16import { areValidationErrors, doesVideoChannelNameWithHostExist } from '../shared' 17import { areValidationErrors, checkUserQuota, doesVideoChannelNameWithHostExist } from '../shared'
17 18
18const videoChannelsAddValidator = [ 19export const videoChannelsAddValidator = [
19 body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), 20 body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'),
20 body('displayName').custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), 21 body('displayName').custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'),
21 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), 22 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'),
@@ -45,7 +46,7 @@ const videoChannelsAddValidator = [
45 } 46 }
46] 47]
47 48
48const videoChannelsUpdateValidator = [ 49export const videoChannelsUpdateValidator = [
49 param('nameWithHost').exists().withMessage('Should have an video channel name with host'), 50 param('nameWithHost').exists().withMessage('Should have an video channel name with host'),
50 body('displayName') 51 body('displayName')
51 .optional() 52 .optional()
@@ -69,7 +70,7 @@ const videoChannelsUpdateValidator = [
69 } 70 }
70] 71]
71 72
72const videoChannelsRemoveValidator = [ 73export const videoChannelsRemoveValidator = [
73 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 74 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
74 logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params }) 75 logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params })
75 76
@@ -79,7 +80,7 @@ const videoChannelsRemoveValidator = [
79 } 80 }
80] 81]
81 82
82const videoChannelsNameWithHostValidator = [ 83export const videoChannelsNameWithHostValidator = [
83 param('nameWithHost').exists().withMessage('Should have an video channel name with host'), 84 param('nameWithHost').exists().withMessage('Should have an video channel name with host'),
84 85
85 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 86 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
@@ -93,7 +94,7 @@ const videoChannelsNameWithHostValidator = [
93 } 94 }
94] 95]
95 96
96const ensureIsLocalChannel = [ 97export const ensureIsLocalChannel = [
97 (req: express.Request, res: express.Response, next: express.NextFunction) => { 98 (req: express.Request, res: express.Response, next: express.NextFunction) => {
98 if (res.locals.videoChannel.Actor.isOwned() === false) { 99 if (res.locals.videoChannel.Actor.isOwned() === false) {
99 return res.fail({ 100 return res.fail({
@@ -106,7 +107,18 @@ const ensureIsLocalChannel = [
106 } 107 }
107] 108]
108 109
109const videoChannelStatsValidator = [ 110export const ensureChannelOwnerCanUpload = [
111 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
112 const channel = res.locals.videoChannel
113 const user = { id: channel.Account.userId }
114
115 if (!await checkUserQuota(user, 1, res)) return
116
117 next()
118 }
119]
120
121export const videoChannelStatsValidator = [
110 query('withStats') 122 query('withStats')
111 .optional() 123 .optional()
112 .customSanitizer(toBooleanOrNull) 124 .customSanitizer(toBooleanOrNull)
@@ -118,7 +130,7 @@ const videoChannelStatsValidator = [
118 } 130 }
119] 131]
120 132
121const videoChannelsListValidator = [ 133export const videoChannelsListValidator = [
122 query('search').optional().not().isEmpty().withMessage('Should have a valid search'), 134 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
123 135
124 (req: express.Request, res: express.Response, next: express.NextFunction) => { 136 (req: express.Request, res: express.Response, next: express.NextFunction) => {
@@ -130,17 +142,24 @@ const videoChannelsListValidator = [
130 } 142 }
131] 143]
132 144
133// --------------------------------------------------------------------------- 145export const videoChannelImportVideosValidator = [
146 body('externalChannelUrl').custom(isUrlValid).withMessage('Should have a valid channel url'),
134 147
135export { 148 (req: express.Request, res: express.Response, next: express.NextFunction) => {
136 videoChannelsAddValidator, 149 logger.debug('Checking videoChannelImport parameters', { parameters: req.body })
137 videoChannelsUpdateValidator, 150
138 videoChannelsRemoveValidator, 151 if (areValidationErrors(req, res)) return
139 videoChannelsNameWithHostValidator, 152
140 ensureIsLocalChannel, 153 if (!CONFIG.IMPORT.VIDEOS.HTTP.ENABLED) {
141 videoChannelsListValidator, 154 return res.fail({
142 videoChannelStatsValidator 155 status: HttpStatusCode.FORBIDDEN_403,
143} 156 message: 'Channel import is impossible as video upload via HTTP is not enabled on the server'
157 })
158 }
159
160 return next()
161 }
162]
144 163
145// --------------------------------------------------------------------------- 164// ---------------------------------------------------------------------------
146 165