From 3b0bd70aa05ab82fa30fe67ed4899d44652c703a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 9 Jun 2020 16:39:45 +0200 Subject: Add search target check params --- server/helpers/custom-validators/search.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'server/helpers') 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 @@ import validator from 'validator' -import { isArray } from './misc' +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)) @@ -13,10 +15,23 @@ 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 + isNSFWQueryValid, + isSearchTargetValid } -- cgit v1.2.3