X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Fhelpers%2Fcustom-validators%2Ffollows.ts;h=8f65552c33ba48525972c0f6859076852b97dda6;hb=75b7117f078461d2507572ba9da6527894e1b734;hp=fbef7ad8712d58a746eb2ea9671de86be91d16a8;hpb=b8f4167fb6fa448125aeecff80b201d74e27fe6a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/follows.ts b/server/helpers/custom-validators/follows.ts index fbef7ad87..8f65552c3 100644 --- a/server/helpers/custom-validators/follows.ts +++ b/server/helpers/custom-validators/follows.ts @@ -1,4 +1,4 @@ -import { exists } from './misc' +import { exists, isArray } from './misc' import { FollowState } from '@shared/models' function isFollowStateValid (value: FollowState) { @@ -7,8 +7,24 @@ function isFollowStateValid (value: FollowState) { return value === 'pending' || value === 'accepted' } +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 }