2020-01-07 08:56:07 -05:00
|
|
|
import validator from 'validator'
|
2020-06-09 10:39:45 -04:00
|
|
|
import { SearchTargetType } from '@shared/models/search/search-target-query.model'
|
|
|
|
import { isArray, exists } from './misc'
|
|
|
|
import { CONFIG } from '@server/initializers/config'
|
2018-07-20 08:35:18 -04:00
|
|
|
|
|
|
|
function isNumberArray (value: any) {
|
|
|
|
return isArray(value) && value.every(v => validator.isInt('' + v))
|
|
|
|
}
|
|
|
|
|
|
|
|
function isStringArray (value: any) {
|
|
|
|
return isArray(value) && value.every(v => typeof v === 'string')
|
|
|
|
}
|
|
|
|
|
2021-05-03 05:06:19 -04:00
|
|
|
function isBooleanBothQueryValid (value: any) {
|
2018-07-20 12:31:49 -04:00
|
|
|
return value === 'true' || value === 'false' || value === 'both'
|
|
|
|
}
|
|
|
|
|
2020-06-09 10:39:45 -04:00
|
|
|
function isSearchTargetValid (value: SearchTargetType) {
|
|
|
|
if (!exists(value)) return true
|
|
|
|
|
|
|
|
const searchIndexConfig = CONFIG.SEARCH.SEARCH_INDEX
|
|
|
|
|
2022-11-23 09:50:34 -05:00
|
|
|
if (value === 'local') return true
|
2020-06-09 10:39:45 -04:00
|
|
|
|
|
|
|
if (value === 'search-index' && searchIndexConfig.ENABLED) return true
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-07-20 08:35:18 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
isNumberArray,
|
2018-07-20 12:31:49 -04:00
|
|
|
isStringArray,
|
2021-05-03 05:06:19 -04:00
|
|
|
isBooleanBothQueryValid,
|
2020-06-09 10:39:45 -04:00
|
|
|
isSearchTargetValid
|
2018-07-20 08:35:18 -04:00
|
|
|
}
|