aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-05-03 15:53:07 +0200
committerChocobozzz <me@florianbigard.com>2021-05-03 16:42:15 +0200
commit1a7d0887b6c22ca6539a15297fd4159d33d7dc48 (patch)
treea6a7c0c55ab0c8af74bb5df7baef13c10cc3ef64 /client/src/app
parent1de8740195bedd0d3d43acf69f443f27364e39ce (diff)
downloadPeerTube-1a7d0887b6c22ca6539a15297fd4159d33d7dc48.tar.gz
PeerTube-1a7d0887b6c22ca6539a15297fd4159d33d7dc48.tar.zst
PeerTube-1a7d0887b6c22ca6539a15297fd4159d33d7dc48.zip
Refactor parseQueryStringFilter boolean handler
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/core/rest/rest.service.ts12
-rw-r--r--client/src/app/core/users/user.service.ts8
-rw-r--r--client/src/app/shared/shared-main/video/video.service.ts8
-rw-r--r--client/src/app/shared/shared-video-comment/video-comment.service.ts8
4 files changed, 12 insertions, 24 deletions
diff --git a/client/src/app/core/rest/rest.service.ts b/client/src/app/core/rest/rest.service.ts
index 4f1fc8848..1696e6709 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 {
90 90
91 const matchedTokens = tokens.filter(t => t.startsWith(prefix)) 91 const matchedTokens = tokens.filter(t => t.startsWith(prefix))
92 .map(t => t.slice(prefix.length)) // Keep the value filter 92 .map(t => t.slice(prefix.length)) // Keep the value filter
93 .map(t => t.replace(/^"|"$/g, '')) 93 .map(t => t.replace(/^"|"$/g, '')) // Remove ""
94 .map(t => { 94 .map(t => {
95 if (prefixObj.handler) return prefixObj.handler(t) 95 if (prefixObj.handler) return prefixObj.handler(t)
96 96
97 if (prefixObj.isBoolean) {
98 if (t === 'true') return true
99 if (t === 'false') return false
100
101 return undefined
102 }
103
97 return t 104 return t
98 }) 105 })
99 .filter(t => !!t || t === 0) 106 .filter(t => t !== null && t !== undefined)
100 .map(t => prefixObj.isBoolean ? t === 'true' : t)
101 107
102 if (matchedTokens.length === 0) continue 108 if (matchedTokens.length === 0) continue
103 109
diff --git a/client/src/app/core/users/user.service.ts b/client/src/app/core/users/user.service.ts
index 3de83152c..47db985e1 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 {
320 const filters = this.restService.parseQueryStringFilter(search, { 320 const filters = this.restService.parseQueryStringFilter(search, {
321 blocked: { 321 blocked: {
322 prefix: 'banned:', 322 prefix: 'banned:',
323 isBoolean: true, 323 isBoolean: true
324 handler: v => {
325 if (v === 'true') return v
326 if (v === 'false') return v
327
328 return undefined
329 }
330 } 324 }
331 }) 325 })
332 326
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 668e51f73..7b17bd2ab 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 {
129 const filters = this.restService.parseQueryStringFilter(search, { 129 const filters = this.restService.parseQueryStringFilter(search, {
130 isLive: { 130 isLive: {
131 prefix: 'isLive:', 131 prefix: 'isLive:',
132 isBoolean: true, 132 isBoolean: true
133 handler: v => {
134 if (v === 'true') return v
135 if (v === 'false') return v
136
137 return undefined
138 }
139 } 133 }
140 }) 134 })
141 135
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 0f09778df..c5aeb3c12 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 {
190 const filters = this.restService.parseQueryStringFilter(search, { 190 const filters = this.restService.parseQueryStringFilter(search, {
191 isLocal: { 191 isLocal: {
192 prefix: 'local:', 192 prefix: 'local:',
193 isBoolean: true, 193 isBoolean: true
194 handler: v => {
195 if (v === 'true') return v
196 if (v === 'false') return v
197
198 return undefined
199 }
200 }, 194 },
201 195
202 searchAccount: { prefix: 'account:' }, 196 searchAccount: { prefix: 'account:' },