From ec07729424be064005045ccee3777338b358147c Mon Sep 17 00:00:00 2001 From: Alain Nussbaumer Date: Wed, 20 Mar 2024 21:37:46 +0100 Subject: [PATCH] [web] Fix error when search queries contain banks or start with blanks. --- web-src/src/pages/PageSearchLibrary.vue | 59 ++++++++++--------------- web-src/src/pages/PageSearchSpotify.vue | 9 ++-- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/web-src/src/pages/PageSearchLibrary.vue b/web-src/src/pages/PageSearchLibrary.vue index 246f3c2b..a43656a9 100644 --- a/web-src/src/pages/PageSearchLibrary.vue +++ b/web-src/src/pages/PageSearchLibrary.vue @@ -311,17 +311,16 @@ export default { methods: { search(route) { - if (!route.query.query || route.query.query === '') { - this.search_query = '' + this.search_query = route.query.query?.trim() + if (!this.search_query) { this.$refs.search_field.focus() return } - - this.search_query = route.query.query + route.query.query = this.search_query this.searchMusic(route.query) this.searchAudiobooks(route.query) this.searchPodcasts(route.query) - this.$store.dispatch('add_recent_search', route.query.query) + this.$store.dispatch('add_recent_search', this.search_query) }, searchMusic(query) { @@ -334,23 +333,19 @@ export default { ) { return } - const searchParams = { - type: query.type, - media_kind: 'music' + type: query.type } - if (query.query.startsWith('query:')) { - searchParams.expression = query.query.replace(/^query:/u, '').trim() + searchParams.expression = `${query.query.replace(/^query:/u, '').trim()} and media_kind is music` } else { searchParams.query = query.query + searchParams.media_kind = 'music' } - if (query.limit) { searchParams.limit = query.limit searchParams.offset = query.offset } - webapi.search(searchParams).then(({ data }) => { this.tracks = new GroupedList(data.tracks) this.artists = new GroupedList(data.artists) @@ -364,24 +359,20 @@ export default { if (query.type.indexOf('audiobook') < 0) { return } - - const searchParams = { - type: 'album', - media_kind: 'audiobook' + const parameters = { + type: 'album' } - if (query.query.startsWith('query:')) { - searchParams.expression = query.query.replace(/^query:/u, '').trim() + parameters.expression = query.query.replace(/^query:/u, '').trim() } else { - searchParams.expression = `((album includes "${query.query}" or artist includes "${query.query}") and media_kind is audiobook)` + parameters.expression = `album includes "${query.query}" or artist includes "${query.query}"` } - + parameters.expression = `(${parameters.expression}) and media_kind is audiobook` if (query.limit) { - searchParams.limit = query.limit - searchParams.offset = query.offset + parameters.limit = query.limit + parameters.offset = query.offset } - - webapi.search(searchParams).then(({ data }) => { + webapi.search(parameters).then(({ data }) => { this.audiobooks = new GroupedList(data.albums) }) }, @@ -390,24 +381,20 @@ export default { if (query.type.indexOf('podcast') < 0) { return } - - const searchParams = { - type: 'album', - media_kind: 'podcast' + const parameters = { + type: 'album' } - if (query.query.startsWith('query:')) { - searchParams.expression = query.query.replace(/^query:/u, '').trim() + parameters.expression = query.query.replace(/^query:/u, '').trim() } else { - searchParams.expression = `((album includes "${query.query}" or artist includes "${query.query}") and media_kind is podcast)` + parameters.expression = `album includes "${query.query}" or artist includes "${query.query}"` } - + parameters.expression = `(${parameters.expression}) and media_kind is podcast` if (query.limit) { - searchParams.limit = query.limit - searchParams.offset = query.offset + parameters.limit = query.limit + parameters.offset = query.offset } - - webapi.search(searchParams).then(({ data }) => { + webapi.search(parameters).then(({ data }) => { this.podcasts = new GroupedList(data.albums) }) }, diff --git a/web-src/src/pages/PageSearchSpotify.vue b/web-src/src/pages/PageSearchSpotify.vue index 8e9c8fd9..216dbce5 100644 --- a/web-src/src/pages/PageSearchSpotify.vue +++ b/web-src/src/pages/PageSearchSpotify.vue @@ -439,17 +439,16 @@ export default { }, search() { this.reset() - // If no search query present reset and focus search field + this.search_query = this.query.query?.trim() if ( - !this.query.query || - this.query.query === '' || - this.query.query.startsWith('query:') + !this.search_query || + this.search_query.startsWith('query:') ) { this.search_query = '' this.$refs.search_field.focus() return } - this.search_query = this.query.query + this.query.query = this.search_query this.search_param.limit = this.query.limit ? this.query.limit : PAGE_SIZE this.search_param.offset = this.query.offset ? this.query.offset : 0 this.$store.dispatch('add_recent_search', this.query.query)