]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/misc.ts
add postgresql96-contrib to the FreeBSD dependencies (#958)
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / misc.ts
index 275482fa19ca2d2c9bc5c1df5fd54106783cc167..6d10a65a881ee75b9f656ebe76aed2d363f1db2e 100644 (file)
@@ -35,16 +35,23 @@ function toIntOrNull (value: string) {
   return validator.toInt(value)
 }
 
-function toStringOrNull (value: string) {
+function toValueOrNull (value: string) {
   if (value === 'null') return null
 
   return value
 }
 
+function toArray (value: string) {
+  if (value && isArray(value) === false) return [ value ]
+
+  return value
+}
+
 function isFileValid (
   files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[],
   mimeTypeRegex: string,
   field: string,
+  maxSize: number | null,
   optional = false
 ) {
   // Should have files
@@ -61,6 +68,9 @@ function isFileValid (
   const file = fileArray[ 0 ]
   if (!file || !file.originalname) return false
 
+  // Check size
+  if ((maxSize !== null) && file.size > maxSize) return false
+
   return new RegExp(`^${mimeTypeRegex}$`, 'i').test(file.mimetype)
 }
 
@@ -73,8 +83,9 @@ export {
   isUUIDValid,
   isIdOrUUIDValid,
   isDateValid,
-  toStringOrNull,
+  toValueOrNull,
   isBooleanValid,
   toIntOrNull,
+  toArray,
   isFileValid
 }