aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/search.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/search.ts')
-rw-r--r--server/helpers/custom-validators/search.ts19
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 @@
1import validator from 'validator' 1import validator from 'validator'
2import { isArray } from './misc' 2import { SearchTargetType } from '@shared/models/search/search-target-query.model'
3import { isArray, exists } from './misc'
4import { CONFIG } from '@server/initializers/config'
3 5
4function isNumberArray (value: any) { 6function 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
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
16// --------------------------------------------------------------------------- 30// ---------------------------------------------------------------------------
17 31
18export { 32export {
19 isNumberArray, 33 isNumberArray,
20 isStringArray, 34 isStringArray,
21 isNSFWQueryValid 35 isNSFWQueryValid,
36 isSearchTargetValid
22} 37}