diff options
Diffstat (limited to 'server/helpers/custom-validators/search.ts')
-rw-r--r-- | server/helpers/custom-validators/search.ts | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/server/helpers/custom-validators/search.ts b/server/helpers/custom-validators/search.ts index bb17134c3..429fcafcf 100644 --- a/server/helpers/custom-validators/search.ts +++ b/server/helpers/custom-validators/search.ts | |||
@@ -1,5 +1,7 @@ | |||
1 | import validator from 'validator' | 1 | import validator from 'validator' |
2 | import { isArray } from './misc' | 2 | import { SearchTargetType } from '@shared/models/search/search-target-query.model' |
3 | import { isArray, exists } from './misc' | ||
4 | import { CONFIG } from '@server/initializers/config' | ||
3 | 5 | ||
4 | function isNumberArray (value: any) { | 6 | function isNumberArray (value: any) { |
5 | return isArray(value) && value.every(v => validator.isInt('' + v)) | 7 | return isArray(value) && value.every(v => validator.isInt('' + v)) |
@@ -13,10 +15,23 @@ function isNSFWQueryValid (value: any) { | |||
13 | return value === 'true' || value === 'false' || value === 'both' | 15 | return value === 'true' || value === 'false' || value === 'both' |
14 | } | 16 | } |
15 | 17 | ||
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 | |||
16 | // --------------------------------------------------------------------------- | 30 | // --------------------------------------------------------------------------- |
17 | 31 | ||
18 | export { | 32 | export { |
19 | isNumberArray, | 33 | isNumberArray, |
20 | isStringArray, | 34 | isStringArray, |
21 | isNSFWQueryValid | 35 | isNSFWQueryValid, |
36 | isSearchTargetValid | ||
22 | } | 37 | } |