diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-08-25 18:36:49 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-08-25 18:36:49 +0200 |
commit | 556ddc319242aafef51bae9301423ecf8701a3af (patch) | |
tree | 413829b522193584df348f0356a702b3222c3419 /server/helpers/custom-validators/pods.ts | |
parent | d15ab38a905e6b50972e6f884917db9198279daf (diff) | |
download | PeerTube-556ddc319242aafef51bae9301423ecf8701a3af.tar.gz PeerTube-556ddc319242aafef51bae9301423ecf8701a3af.tar.zst PeerTube-556ddc319242aafef51bae9301423ecf8701a3af.zip |
Upgrade common server dependencies
Diffstat (limited to 'server/helpers/custom-validators/pods.ts')
-rw-r--r-- | server/helpers/custom-validators/pods.ts | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/server/helpers/custom-validators/pods.ts b/server/helpers/custom-validators/pods.ts index 0519def52..f2ca520c0 100644 --- a/server/helpers/custom-validators/pods.ts +++ b/server/helpers/custom-validators/pods.ts | |||
@@ -1,9 +1,20 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | 2 | ||
3 | import { isArray, exists } from './misc' | 3 | import { isArray, exists } from './misc' |
4 | import { isTestInstance } from '../core-utils' | ||
4 | 5 | ||
5 | function isHostValid (host: string) { | 6 | function isHostValid (host: string) { |
6 | return exists(host) && validator.isURL(host) && host.split('://').length === 1 | 7 | const isURLOptions = { |
8 | require_host: true, | ||
9 | require_tld: true | ||
10 | } | ||
11 | |||
12 | // We validate 'localhost', so we don't have the top level domain | ||
13 | if (isTestInstance()) { | ||
14 | isURLOptions.require_tld = false | ||
15 | } | ||
16 | |||
17 | return exists(host) && validator.isURL(host, isURLOptions) && host.split('://').length === 1 | ||
7 | } | 18 | } |
8 | 19 | ||
9 | function isEachUniqueHostValid (hosts: string[]) { | 20 | function isEachUniqueHostValid (hosts: string[]) { |
@@ -21,11 +32,9 @@ export { | |||
21 | isHostValid | 32 | isHostValid |
22 | } | 33 | } |
23 | 34 | ||
24 | declare global { | 35 | declare module 'express-validator' { |
25 | namespace ExpressValidator { | 36 | export interface Validator { |
26 | export interface Validator { | 37 | isEachUniqueHostValid |
27 | isEachUniqueHostValid | 38 | isHostValid |
28 | isHostValid | ||
29 | } | ||
30 | } | 39 | } |
31 | } | 40 | } |