]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/misc.ts
Prevent caption listing of private videos
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / misc.ts
index 528bfcfb851eec54d815177402ae0860c8e4c9eb..c19a3e5eba2692e7f1e87075d20509ede9bba365 100644 (file)
@@ -23,6 +23,10 @@ function isNotEmptyIntArray (value: any) {
   return Array.isArray(value) && value.every(v => validator.isInt('' + v)) && value.length !== 0
 }
 
+function isNotEmptyStringArray (value: any) {
+  return Array.isArray(value) && value.every(v => typeof v === 'string' && v.length !== 0) && value.length !== 0
+}
+
 function isArrayOf (value: any, validator: (value: any) => boolean) {
   return isArray(value) && value.every(v => validator(v))
 }
@@ -39,6 +43,10 @@ function isUUIDValid (value: string) {
   return exists(value) && validator.isUUID('' + value, 4)
 }
 
+function areUUIDsValid (values: string[]) {
+  return isArray(values) && values.every(v => isUUIDValid(v))
+}
+
 function isIdOrUUIDValid (value: string) {
   return isIdValid(value) || isUUIDValid(value)
 }
@@ -132,6 +140,10 @@ function toCompleteUUID (value: string) {
   return value
 }
 
+function toCompleteUUIDs (values: string[]) {
+  return values.map(v => toCompleteUUID(v))
+}
+
 function toIntOrNull (value: string) {
   const v = toValueOrNull(value)
 
@@ -179,7 +191,9 @@ export {
   isIntOrNull,
   isIdValid,
   isSafePath,
+  isNotEmptyStringArray,
   isUUIDValid,
+  toCompleteUUIDs,
   toCompleteUUID,
   isIdOrUUIDValid,
   isDateValid,
@@ -187,6 +201,7 @@ export {
   toBooleanOrNull,
   isBooleanValid,
   toIntOrNull,
+  areUUIDsValid,
   toArray,
   toIntArray,
   isFileFieldValid,