1
0
Fork 0
peertube/server/helpers/custom-validators/follows.ts
Chocobozzz 927fa4b11f
Add rejected state to follows
Prevent reprocessing already rejected follows
2022-07-27 13:52:13 +02:00

30 lines
801 B
TypeScript

import { exists, isArray } from './misc'
import { FollowState } from '@shared/models'
function isFollowStateValid (value: FollowState) {
if (!exists(value)) return false
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,
isRemoteHandleValid,
isEachUniqueHandleValid
}