X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fpods.ts;h=d5021bf38dbf5b8f553af001b87e5fe06a59128e;hb=51548b31815c6f96f314ae96588a9adca150519d;hp=ec9f26cc8444caab3671f06870f4fc31ea8ed488;hpb=69818c9394366b954b6ba3bd697bd9d2b09f2a16;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/pods.ts b/server/helpers/custom-validators/pods.ts index ec9f26cc8..d5021bf38 100644 --- a/server/helpers/custom-validators/pods.ts +++ b/server/helpers/custom-validators/pods.ts @@ -1,15 +1,27 @@ import * as validator from 'validator' +import 'express-validator' import { isArray, exists } from './misc' +import { isTestInstance } from '../core-utils' function isHostValid (host: string) { - return exists(host) && validator.isURL(host) && host.split('://').length === 1 + const isURLOptions = { + require_host: true, + require_tld: true + } + + // We validate 'localhost', so we don't have the top level domain + if (isTestInstance()) { + isURLOptions.require_tld = false + } + + return exists(host) && validator.isURL(host, isURLOptions) && host.split('://').length === 1 } function isEachUniqueHostValid (hosts: string[]) { return isArray(hosts) && hosts.length !== 0 && - hosts.every(function (host) { + hosts.every(host => { return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host) }) } @@ -20,12 +32,3 @@ export { isEachUniqueHostValid, isHostValid } - -declare global { - namespace ExpressValidator { - export interface Validator { - isEachUniqueHostValid - isHostValid - } - } -}