]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/servers.ts
Merge branch 'release/5.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / servers.ts
index d5021bf38dbf5b8f553af001b87e5fe06a59128e..94fda05aad258eef563bdc14471043cc534ce05a 100644 (file)
@@ -1,8 +1,7 @@
-import * as validator from 'validator'
-import 'express-validator'
-
-import { isArray, exists } from './misc'
-import { isTestInstance } from '../core-utils'
+import validator from 'validator'
+import { CONFIG } from '@server/initializers/config'
+import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
+import { exists, isArray } from './misc'
 
 function isHostValid (host: string) {
   const isURLOptions = {
@@ -11,7 +10,7 @@ function isHostValid (host: string) {
   }
 
   // We validate 'localhost', so we don't have the top level domain
-  if (isTestInstance()) {
+  if (CONFIG.WEBSERVER.HOSTNAME === 'localhost') {
     isURLOptions.require_tld = false
   }
 
@@ -20,15 +19,24 @@ function isHostValid (host: string) {
 
 function isEachUniqueHostValid (hosts: string[]) {
   return isArray(hosts) &&
-    hosts.length !== 0 &&
     hosts.every(host => {
       return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host)
     })
 }
 
+function isValidContactBody (value: any) {
+  return exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.CONTACT_FORM.BODY)
+}
+
+function isValidContactFromName (value: any) {
+  return exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.CONTACT_FORM.FROM_NAME)
+}
+
 // ---------------------------------------------------------------------------
 
 export {
+  isValidContactBody,
+  isValidContactFromName,
   isEachUniqueHostValid,
   isHostValid
 }