X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fsearch.ts;h=a8f25883832c4588b122eee4a801904a5bcf136a;hb=8f581725651c4b2c213d75fc028e306bbf239d3e;hp=15b389a58e5969f36070c1cd59e859ec737c8d9f;hpb=0b18f4aa80df8868bf34605423c7a298dffbb2aa;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/search.ts b/server/helpers/custom-validators/search.ts index 15b389a58..a8f258838 100644 --- a/server/helpers/custom-validators/search.ts +++ b/server/helpers/custom-validators/search.ts @@ -1,7 +1,7 @@ -import * as validator from 'validator' -import 'express-validator' - -import { isArray } from './misc' +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)) @@ -11,14 +11,27 @@ function isStringArray (value: any) { return isArray(value) && value.every(v => typeof v === 'string') } -function isNSFWQueryValid (value: any) { +function isBooleanBothQueryValid (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 + isBooleanBothQueryValid, + isSearchTargetValid }