blob: 429fcafcf9525f94e392f88baeb687a559d88a36 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
import validator from 'validator'
import { SearchTargetType } from '@shared/models/search/search-target-query.model'
import { isArray, exists } from './misc'
import { CONFIG } from '@server/initializers/config'
function isNumberArray (value: any) {
return isArray(value) && value.every(v => validator.isInt('' + v))
}
function isStringArray (value: any) {
return isArray(value) && value.every(v => typeof v === 'string')
}
function isNSFWQueryValid (value: any) {
return value === 'true' || value === 'false' || value === 'both'
}
function isSearchTargetValid (value: SearchTargetType) {
if (!exists(value)) return true
const searchIndexConfig = CONFIG.SEARCH.SEARCH_INDEX
if (value === 'local' && (!searchIndexConfig.ENABLED || !searchIndexConfig.DISABLE_LOCAL_SEARCH)) return true
if (value === 'search-index' && searchIndexConfig.ENABLED) return true
return false
}
// ---------------------------------------------------------------------------
export {
isNumberArray,
isStringArray,
isNSFWQueryValid,
isSearchTargetValid
}
|