Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Refactor parseQueryStringFilter boolean handler

Chocobozzz1a7d0887b6c2
diff --git a/client/src/app/core/rest/rest.service.ts b/client/src/app/core/rest/rest.service.ts
index 4f1fc88484..1696e67098 100644
--- a/client/src/app/core/rest/rest.service.ts
+++ b/client/src/app/core/rest/rest.service.ts
@@ -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
diff --git a/client/src/app/core/users/user.service.ts b/client/src/app/core/users/user.service.ts
index 3de83152c3..47db985e12 100644
--- a/client/src/app/core/users/user.service.ts
+++ b/client/src/app/core/users/user.service.ts
@@ -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
}
})
diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts
index 668e51f735..7b17bd2ab4 100644
--- a/client/src/app/shared/shared-main/video/video.service.ts
+++ b/client/src/app/shared/shared-main/video/video.service.ts
@@ -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
}
})
diff --git a/client/src/app/shared/shared-video-comment/video-comment.service.ts b/client/src/app/shared/shared-video-comment/video-comment.service.ts
index 0f09778df5..c5aeb3c12e 100644
--- a/client/src/app/shared/shared-video-comment/video-comment.service.ts
+++ b/client/src/app/shared/shared-video-comment/video-comment.service.ts
@@ -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:' },