Verified Commit 1a7d0887 authored by Chocobozzz's avatar Chocobozzz
Browse files

Refactor parseQueryStringFilter boolean handler

parent 1de87401
......@@ -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
......
......@@ -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
}
})
......
......@@ -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
}
})
......
......@@ -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:' },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment