aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/search.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-09 16:39:45 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-10 14:02:41 +0200
commit3b0bd70aa05ab82fa30fe67ed4899d44652c703a (patch)
tree662655e40f0a4263f1d3ab457d9970c344e8bbb0 /server/helpers/custom-validators/search.ts
parent7c87746e4b336e547b1917f274c9a0bdc4d1d3df (diff)
downloadPeerTube-3b0bd70aa05ab82fa30fe67ed4899d44652c703a.tar.gz
PeerTube-3b0bd70aa05ab82fa30fe67ed4899d44652c703a.tar.zst
PeerTube-3b0bd70aa05ab82fa30fe67ed4899d44652c703a.zip
Add search target check params
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}