Refactor parseQueryStringFilter boolean handler

This commit is contained in:
Chocobozzz 2021-05-03 15:53:07 +02:00
parent 1de8740195
commit 1a7d0887b6
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 12 additions and 24 deletions

View File

@ -90,14 +90,20 @@ export class RestService {
const matchedTokens = tokens.filter(t => t.startsWith(prefix))
.map(t => t.slice(prefix.length)) // Keep the value filter
.map(t => t.replace(/^"|"$/g, ''))
.map(t => t.replace(/^"|"$/g, '')) // Remove ""
.map(t => {
if (prefixObj.handler) return prefixObj.handler(t)
if (prefixObj.isBoolean) {
if (t === 'true') return true
if (t === 'false') return false
return undefined
}
return t
})
.filter(t => !!t || t === 0)
.map(t => prefixObj.isBoolean ? t === 'true' : t)
.filter(t => t !== null && t !== undefined)
if (matchedTokens.length === 0) continue

View File

@ -320,13 +320,7 @@ export class UserService {
const filters = this.restService.parseQueryStringFilter(search, {
blocked: {
prefix: 'banned:',
isBoolean: true,
handler: v => {
if (v === 'true') return v
if (v === 'false') return v
return undefined
}
isBoolean: true
}
})

View File

@ -129,13 +129,7 @@ export class VideoService implements VideosProvider {
const filters = this.restService.parseQueryStringFilter(search, {
isLive: {
prefix: 'isLive:',
isBoolean: true,
handler: v => {
if (v === 'true') return v
if (v === 'false') return v
return undefined
}
isBoolean: true
}
})

View File

@ -190,13 +190,7 @@ export class VideoCommentService {
const filters = this.restService.parseQueryStringFilter(search, {
isLocal: {
prefix: 'local:',
isBoolean: true,
handler: v => {
if (v === 'true') return v
if (v === 'false') return v
return undefined
}
isBoolean: true
},
searchAccount: { prefix: 'account:' },