Browse Source

refactor(SearchMusare): don't use regex by default and fix frontend error if no songs are returned

Kristian Vos 3 years ago
parent
commit
fb8f2edfaf
2 changed files with 15 additions and 9 deletions
  1. 8 2
      backend/logic/songs.js
  2. 7 7
      frontend/src/mixins/SearchMusare.vue

+ 8 - 2
backend/logic/songs.js

@@ -613,13 +613,19 @@ class _SongsModule extends CoreClass {
 						if (payload.includeVerified) statuses.push("verified");
 						if (statuses.length === 0) return next("No statuses have been included.");
 
+						let { query } = payload;
+
+						const isRegex = query.length > 2 && query.indexOf("/") === 0 && query.lastIndexOf("/") === query.length - 1;
+						if (isRegex) query = query.slice(1, query.length - 1);
+						else query = query.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&');
+
 						const filterArray = [
 							{
-								title: new RegExp(`${payload.query}`, "i"),
+								title: new RegExp(`${query}`, "i"),
 								status: { $in: statuses }
 							},
 							{
-								artists: new RegExp(`${payload.query}`, "i"),
+								artists: new RegExp(`${query}`, "i"),
 								status: { $in: statuses }
 							}
 						];

+ 7 - 7
frontend/src/mixins/SearchMusare.vue

@@ -41,15 +41,15 @@ export default {
 				this.musareSearch.query,
 				page,
 				res => {
-					const { data } = res;
-					const { count, pageSize, songs } = data;
+					if (res.status === "success") {
+						const { data } = res;
+						const { count, pageSize, songs } = data;
 
-					const newSongs = songs.map(song => ({
-						isAddedToQueue: false,
-						...song
-					}));
+						const newSongs = songs.map(song => ({
+							isAddedToQueue: false,
+							...song
+						}));
 
-					if (res.status === "success") {
 						this.musareSearch.results = [
 							...this.musareSearch.results,
 							...newSongs