mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-10 12:26:35 +03:00
Refactor parseQueryStringFilter boolean handler
This commit is contained in:
parent
1de8740195
commit
1a7d0887b6
@ -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:' },
|
||||
|
Loading…
Reference in New Issue
Block a user