From 4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Jul 2021 14:15:15 +0200 Subject: Add ability for instances to follow any actor --- server/helpers/custom-validators/follows.ts | 20 ++++++++++++++++++-- server/helpers/custom-validators/servers.ts | 1 - 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'server/helpers') 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 } diff --git a/server/helpers/custom-validators/servers.ts b/server/helpers/custom-validators/servers.ts index adf1ea497..c0f8b6aeb 100644 --- a/server/helpers/custom-validators/servers.ts +++ b/server/helpers/custom-validators/servers.ts @@ -19,7 +19,6 @@ function isHostValid (host: string) { function isEachUniqueHostValid (hosts: string[]) { return isArray(hosts) && - hosts.length !== 0 && hosts.every(host => { return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host) }) -- cgit v1.2.3