mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Add search target check params
This commit is contained in:
parent
7c87746e4b
commit
3b0bd70aa0
6 changed files with 103 additions and 11 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue