]>
Commit | Line | Data |
---|---|---|
7cde3b9c | 1 | import validator from 'validator' |
3b0bd70a C |
2 | import { SearchTargetType } from '@shared/models/search/search-target-query.model' |
3 | import { isArray, exists } from './misc' | |
4 | import { CONFIG } from '@server/initializers/config' | |
d525fc39 C |
5 | |
6 | function isNumberArray (value: any) { | |
7 | return isArray(value) && value.every(v => validator.isInt('' + v)) | |
8 | } | |
9 | ||
10 | function isStringArray (value: any) { | |
11 | return isArray(value) && value.every(v => typeof v === 'string') | |
12 | } | |
13 | ||
1fd61899 | 14 | function isBooleanBothQueryValid (value: any) { |
0b18f4aa C |
15 | return value === 'true' || value === 'false' || value === 'both' |
16 | } | |
17 | ||
3b0bd70a C |
18 | function 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 | ||
32 | export { | |
33 | isNumberArray, | |
0b18f4aa | 34 | isStringArray, |
1fd61899 | 35 | isBooleanBothQueryValid, |
3b0bd70a | 36 | isSearchTargetValid |
d525fc39 | 37 | } |