diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/helpers/custom-validators/follows.ts | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'server/helpers/custom-validators/follows.ts')
-rw-r--r-- | server/helpers/custom-validators/follows.ts | 20 |
1 files changed, 18 insertions, 2 deletions
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 @@ | |||
1 | import { exists } from './misc' | 1 | import { exists, isArray } from './misc' |
2 | import { FollowState } from '@shared/models' | 2 | import { FollowState } from '@shared/models' |
3 | 3 | ||
4 | function isFollowStateValid (value: FollowState) { | 4 | function isFollowStateValid (value: FollowState) { |
@@ -7,8 +7,24 @@ function isFollowStateValid (value: FollowState) { | |||
7 | return value === 'pending' || value === 'accepted' | 7 | return value === 'pending' || value === 'accepted' |
8 | } | 8 | } |
9 | 9 | ||
10 | function isRemoteHandleValid (value: string) { | ||
11 | if (!exists(value)) return false | ||
12 | if (typeof value !== 'string') return false | ||
13 | |||
14 | return value.includes('@') | ||
15 | } | ||
16 | |||
17 | function isEachUniqueHandleValid (handles: string[]) { | ||
18 | return isArray(handles) && | ||
19 | handles.every(handle => { | ||
20 | return isRemoteHandleValid(handle) && handles.indexOf(handle) === handles.lastIndexOf(handle) | ||
21 | }) | ||
22 | } | ||
23 | |||
10 | // --------------------------------------------------------------------------- | 24 | // --------------------------------------------------------------------------- |
11 | 25 | ||
12 | export { | 26 | export { |
13 | isFollowStateValid | 27 | isFollowStateValid, |
28 | isRemoteHandleValid, | ||
29 | isEachUniqueHandleValid | ||
14 | } | 30 | } |