]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/helpers/custom-validators/pods.ts
Update webpack config
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / pods.ts
... / ...
CommitLineData
1import * as validator from 'validator'
2
3import { isArray, exists } from './misc'
4import { isTestInstance } from '../core-utils'
5
6function isHostValid (host: string) {
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
18}
19
20function isEachUniqueHostValid (hosts: string[]) {
21 return isArray(hosts) &&
22 hosts.length !== 0 &&
23 hosts.every(host => {
24 return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host)
25 })
26}
27
28// ---------------------------------------------------------------------------
29
30export {
31 isEachUniqueHostValid,
32 isHostValid
33}
34
35declare module 'express-validator' {
36 export interface Validator {
37 isEachUniqueHostValid
38 isHostValid
39 }
40}