X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fmisc.ts;h=c19a3e5eba2692e7f1e87075d20509ede9bba365;hb=795212f7acc690c88c86d0fab8772f6564d59cb8;hp=528bfcfb851eec54d815177402ae0860c8e4c9eb;hpb=cf21b2cbef61929177b9c09b5e017c3b7eb8535d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 528bfcfb8..c19a3e5eb 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts @@ -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,