diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-09 16:39:45 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-10 14:02:41 +0200 |
commit | 3b0bd70aa05ab82fa30fe67ed4899d44652c703a (patch) | |
tree | 662655e40f0a4263f1d3ab457d9970c344e8bbb0 /server/helpers/custom-validators | |
parent | 7c87746e4b336e547b1917f274c9a0bdc4d1d3df (diff) | |
download | PeerTube-3b0bd70aa05ab82fa30fe67ed4899d44652c703a.tar.gz PeerTube-3b0bd70aa05ab82fa30fe67ed4899d44652c703a.tar.zst PeerTube-3b0bd70aa05ab82fa30fe67ed4899d44652c703a.zip |
Add search target check params
Diffstat (limited to 'server/helpers/custom-validators')
-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 | } |