aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/pods.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-08-25 18:36:49 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-08-25 18:36:49 +0200
commit556ddc319242aafef51bae9301423ecf8701a3af (patch)
tree413829b522193584df348f0356a702b3222c3419 /server/helpers/custom-validators/pods.ts
parentd15ab38a905e6b50972e6f884917db9198279daf (diff)
downloadPeerTube-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.ts23
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 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2 2
3import { isArray, exists } from './misc' 3import { isArray, exists } from './misc'
4import { isTestInstance } from '../core-utils'
4 5
5function isHostValid (host: string) { 6function 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
9function isEachUniqueHostValid (hosts: string[]) { 20function isEachUniqueHostValid (hosts: string[]) {
@@ -21,11 +32,9 @@ export {
21 isHostValid 32 isHostValid
22} 33}
23 34
24declare global { 35declare 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}