]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/custom-validators/search.ts
Disable openapi generation
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / search.ts
CommitLineData
7cde3b9c 1import validator from 'validator'
3b0bd70a
C
2import { SearchTargetType } from '@shared/models/search/search-target-query.model'
3import { isArray, exists } from './misc'
4import { CONFIG } from '@server/initializers/config'
d525fc39
C
5
6function isNumberArray (value: any) {
7 return isArray(value) && value.every(v => validator.isInt('' + v))
8}
9
10function isStringArray (value: any) {
11 return isArray(value) && value.every(v => typeof v === 'string')
12}
13
1fd61899 14function isBooleanBothQueryValid (value: any) {
0b18f4aa
C
15 return value === 'true' || value === 'false' || value === 'both'
16}
17
3b0bd70a
C
18function isSearchTargetValid (value: SearchTargetType) {
19 if (!exists(value)) return true
20
21 const searchIndexConfig = CONFIG.SEARCH.SEARCH_INDEX
22
23 if (value === 'local' && (!searchIndexConfig.ENABLED || !searchIndexConfig.DISABLE_LOCAL_SEARCH)) return true
24
25 if (value === 'search-index' && searchIndexConfig.ENABLED) return true
26
27 return false
28}
29
d525fc39
C
30// ---------------------------------------------------------------------------
31
32export {
33 isNumberArray,
0b18f4aa 34 isStringArray,
1fd61899 35 isBooleanBothQueryValid,
3b0bd70a 36 isSearchTargetValid
d525fc39 37}