]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/misc.ts
Feature/filter already watched videos (#5739)
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / misc.ts
index 17750379de66946b186ef7d476b50ac1957891cf..ebab4c6b244ba1277a0424c089e535fd9faac131 100644 (file)
@@ -15,6 +15,10 @@ function isSafePath (p: string) {
     })
 }
 
+function isSafePeerTubeFilenameWithoutExtension (filename: string) {
+  return filename.match(/^[a-z0-9-]+$/)
+}
+
 function isArray (value: any): value is any[] {
   return Array.isArray(value)
 }
@@ -86,7 +90,7 @@ function isFileValid (options: {
 
   // The file exists
   const file = fileArray[0]
-  if (!file || !file.originalname) return false
+  if (!file?.originalname) return false
 
   // Check size
   if ((maxSize !== null) && file.size > maxSize) return false
@@ -103,7 +107,13 @@ function checkMimetypeRegex (fileMimeType: string, mimeTypeRegex: string) {
 // ---------------------------------------------------------------------------
 
 function toCompleteUUID (value: string) {
-  if (isShortUUID(value)) return shortToUUID(value)
+  if (isShortUUID(value)) {
+    try {
+      return shortToUUID(value)
+    } catch {
+      return null
+    }
+  }
 
   return value
 }
@@ -166,5 +176,6 @@ export {
   areUUIDsValid,
   toIntArray,
   isFileValid,
+  isSafePeerTubeFilenameWithoutExtension,
   checkMimetypeRegex
 }