]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/pods.ts
Add follow tabs
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / pods.ts
index ec9f26cc8444caab3671f06870f4fc31ea8ed488..d5021bf38dbf5b8f553af001b87e5fe06a59128e 100644 (file)
@@ -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
-    }
-  }
-}