]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/follows.ts
Don't use safe mode when normalizing
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / follows.ts
index fbef7ad8712d58a746eb2ea9671de86be91d16a8..0bec683c167481d07447b1388f786ef187c481a1 100644 (file)
@@ -1,14 +1,30 @@
-import { exists } from './misc'
+import { exists, isArray } from './misc'
 import { FollowState } from '@shared/models'
 
 function isFollowStateValid (value: FollowState) {
   if (!exists(value)) return false
 
-  return value === 'pending' || value === 'accepted'
+  return value === 'pending' || value === 'accepted' || value === 'rejected'
+}
+
+function isRemoteHandleValid (value: string) {
+  if (!exists(value)) return false
+  if (typeof value !== 'string') return false
+
+  return value.includes('@')
+}
+
+function isEachUniqueHandleValid (handles: string[]) {
+  return isArray(handles) &&
+    handles.every(handle => {
+      return isRemoteHandleValid(handle) && handles.indexOf(handle) === handles.lastIndexOf(handle)
+    })
 }
 
 // ---------------------------------------------------------------------------
 
 export {
-  isFollowStateValid
+  isFollowStateValid,
+  isRemoteHandleValid,
+  isEachUniqueHandleValid
 }