diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-11 11:33:44 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-11 13:45:39 +0200 |
commit | 6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0 (patch) | |
tree | b47de7efb8c6c611c63a15a971c6125a278f547a /server/middlewares/validators | |
parent | 2c3abc4fa796555eb7d25f416c4f41ab3e3ad8ca (diff) | |
download | PeerTube-6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0.tar.gz PeerTube-6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0.tar.zst PeerTube-6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0.zip |
Move config in its own file
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/blocklist.ts | 5 | ||||
-rw-r--r-- | server/middlewares/validators/follows.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/oembed.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/server.ts | 2 | ||||
-rw-r--r-- | server/middlewares/validators/user-subscriptions.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/videos/video-imports.ts | 2 | ||||
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 3 |
7 files changed, 12 insertions, 12 deletions
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts index f5b295f45..7c494de78 100644 --- a/server/middlewares/validators/blocklist.ts +++ b/server/middlewares/validators/blocklist.ts | |||
@@ -3,13 +3,12 @@ import * as express from 'express' | |||
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | import { doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' | 5 | import { doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' |
6 | import { UserModel } from '../../models/account/user' | ||
7 | import { AccountBlocklistModel } from '../../models/account/account-blocklist' | 6 | import { AccountBlocklistModel } from '../../models/account/account-blocklist' |
8 | import { isHostValid } from '../../helpers/custom-validators/servers' | 7 | import { isHostValid } from '../../helpers/custom-validators/servers' |
9 | import { ServerBlocklistModel } from '../../models/server/server-blocklist' | 8 | import { ServerBlocklistModel } from '../../models/server/server-blocklist' |
10 | import { ServerModel } from '../../models/server/server' | 9 | import { ServerModel } from '../../models/server/server' |
11 | import { CONFIG } from '../../initializers' | ||
12 | import { getServerActor } from '../../helpers/utils' | 10 | import { getServerActor } from '../../helpers/utils' |
11 | import { WEBSERVER } from '../../initializers/constants' | ||
13 | 12 | ||
14 | const blockAccountValidator = [ | 13 | const blockAccountValidator = [ |
15 | body('accountName').exists().withMessage('Should have an account name with host'), | 14 | body('accountName').exists().withMessage('Should have an account name with host'), |
@@ -79,7 +78,7 @@ const blockServerValidator = [ | |||
79 | 78 | ||
80 | const host: string = req.body.host | 79 | const host: string = req.body.host |
81 | 80 | ||
82 | if (host === CONFIG.WEBSERVER.HOST) { | 81 | if (host === WEBSERVER.HOST) { |
83 | return res.status(409) | 82 | return res.status(409) |
84 | .send({ error: 'You cannot block your own server.' }) | 83 | .send({ error: 'You cannot block your own server.' }) |
85 | .end() | 84 | .end() |
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index b360cf95e..5623b4ba6 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts | |||
@@ -4,7 +4,7 @@ import { isTestInstance } from '../../helpers/core-utils' | |||
4 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' | 4 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' |
5 | import { logger } from '../../helpers/logger' | 5 | import { logger } from '../../helpers/logger' |
6 | import { getServerActor } from '../../helpers/utils' | 6 | import { getServerActor } from '../../helpers/utils' |
7 | import { CONFIG, SERVER_ACTOR_NAME } from '../../initializers' | 7 | import { SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers' |
8 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | 8 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
9 | import { areValidationErrors } from './utils' | 9 | import { areValidationErrors } from './utils' |
10 | import { ActorModel } from '../../models/activitypub/actor' | 10 | import { ActorModel } from '../../models/activitypub/actor' |
@@ -16,7 +16,7 @@ const followValidator = [ | |||
16 | 16 | ||
17 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 17 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
18 | // Force https if the administrator wants to make friends | 18 | // Force https if the administrator wants to make friends |
19 | if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') { | 19 | if (isTestInstance() === false && WEBSERVER.SCHEME === 'http') { |
20 | return res.status(500) | 20 | return res.status(500) |
21 | .json({ | 21 | .json({ |
22 | error: 'Cannot follow on a non HTTPS web server.' | 22 | error: 'Cannot follow on a non HTTPS web server.' |
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index c89bc26de..0bb908d0b 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts | |||
@@ -5,10 +5,10 @@ import { isTestInstance } from '../../helpers/core-utils' | |||
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
6 | import { doesVideoExist } from '../../helpers/custom-validators/videos' | 6 | import { doesVideoExist } from '../../helpers/custom-validators/videos' |
7 | import { logger } from '../../helpers/logger' | 7 | import { logger } from '../../helpers/logger' |
8 | import { CONFIG } from '../../initializers' | ||
9 | import { areValidationErrors } from './utils' | 8 | import { areValidationErrors } from './utils' |
9 | import { WEBSERVER } from '../../initializers/constants' | ||
10 | 10 | ||
11 | const urlShouldStartWith = CONFIG.WEBSERVER.SCHEME + '://' + join(CONFIG.WEBSERVER.HOST, 'videos', 'watch') + '/' | 11 | const urlShouldStartWith = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/' |
12 | const videoWatchRegex = new RegExp('([^/]+)$') | 12 | const videoWatchRegex = new RegExp('([^/]+)$') |
13 | const isURLOptions = { | 13 | const isURLOptions = { |
14 | require_host: true, | 14 | require_host: true, |
diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts index e62a17163..6eff8e9ee 100644 --- a/server/middlewares/validators/server.ts +++ b/server/middlewares/validators/server.ts | |||
@@ -7,7 +7,7 @@ import { body } from 'express-validator/check' | |||
7 | import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' | 7 | import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' |
8 | import { Emailer } from '../../lib/emailer' | 8 | import { Emailer } from '../../lib/emailer' |
9 | import { Redis } from '../../lib/redis' | 9 | import { Redis } from '../../lib/redis' |
10 | import { CONFIG } from '../../initializers/constants' | 10 | import { CONFIG } from '../../initializers/config' |
11 | 11 | ||
12 | const serverGetValidator = [ | 12 | const serverGetValidator = [ |
13 | body('host').custom(isHostValid).withMessage('Should have a valid host'), | 13 | body('host').custom(isHostValid).withMessage('Should have a valid host'), |
diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts index fd82ed017..2356745d7 100644 --- a/server/middlewares/validators/user-subscriptions.ts +++ b/server/middlewares/validators/user-subscriptions.ts | |||
@@ -5,8 +5,8 @@ import { logger } from '../../helpers/logger' | |||
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
6 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | 6 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
7 | import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' | 7 | import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' |
8 | import { CONFIG } from '../../initializers' | ||
9 | import { toArray } from '../../helpers/custom-validators/misc' | 8 | import { toArray } from '../../helpers/custom-validators/misc' |
9 | import { WEBSERVER } from '../../initializers/constants' | ||
10 | 10 | ||
11 | const userSubscriptionAddValidator = [ | 11 | const userSubscriptionAddValidator = [ |
12 | body('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'), | 12 | body('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'), |
@@ -43,7 +43,7 @@ const userSubscriptionGetValidator = [ | |||
43 | if (areValidationErrors(req, res)) return | 43 | if (areValidationErrors(req, res)) return |
44 | 44 | ||
45 | let [ name, host ] = req.params.uri.split('@') | 45 | let [ name, host ] = req.params.uri.split('@') |
46 | if (host === CONFIG.WEBSERVER.HOST) host = null | 46 | if (host === WEBSERVER.HOST) host = null |
47 | 47 | ||
48 | const user = res.locals.oauth.token.User | 48 | const user = res.locals.oauth.token.User |
49 | const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(user.Account.Actor.id, name, host) | 49 | const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(user.Account.Actor.id, name, host) |
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index 3d662b20f..fb13f3ceb 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts | |||
@@ -7,7 +7,7 @@ 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' | 8 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
9 | import { doesVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' | 9 | import { doesVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' |
10 | import { CONFIG } from '../../../initializers/constants' | 10 | import { CONFIG } from '../../../initializers/config' |
11 | import { CONSTRAINTS_FIELDS } from '../../../initializers' | 11 | import { CONSTRAINTS_FIELDS } from '../../../initializers' |
12 | 12 | ||
13 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ | 13 | const videoImportAddValidator = getCommonVideoEditAttributes().concat([ |
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index e247db708..7ce1a922f 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -32,7 +32,7 @@ import { | |||
32 | } from '../../../helpers/custom-validators/videos' | 32 | } from '../../../helpers/custom-validators/videos' |
33 | import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' | 33 | import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' |
34 | import { logger } from '../../../helpers/logger' | 34 | import { logger } from '../../../helpers/logger' |
35 | import { CONFIG, CONSTRAINTS_FIELDS } from '../../../initializers' | 35 | import { CONSTRAINTS_FIELDS } from '../../../initializers' |
36 | import { authenticatePromiseIfNeeded } from '../../oauth' | 36 | import { authenticatePromiseIfNeeded } from '../../oauth' |
37 | import { areValidationErrors } from '../utils' | 37 | import { areValidationErrors } from '../utils' |
38 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 38 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
@@ -43,6 +43,7 @@ import { AccountModel } from '../../../models/account/account' | |||
43 | import { VideoFetchType } from '../../../helpers/video' | 43 | import { VideoFetchType } from '../../../helpers/video' |
44 | import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search' | 44 | import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search' |
45 | import { getServerActor } from '../../../helpers/utils' | 45 | import { getServerActor } from '../../../helpers/utils' |
46 | import { CONFIG } from '../../../initializers/config' | ||
46 | 47 | ||
47 | const videosAddValidator = getCommonVideoEditAttributes().concat([ | 48 | const videosAddValidator = getCommonVideoEditAttributes().concat([ |
48 | body('videofile') | 49 | body('videofile') |