From 42264d0353d39a565d566d9c349b56d22f16ed71 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Wed, 8 Apr 2020 19:01:50 +0200 Subject: [PATCH] Moved distinction between URL and Search query to frontend --- public/index.html | 1 + public/js/frontend.js | 5 ++++- public/js/utils.js | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 public/js/utils.js diff --git a/public/index.html b/public/index.html index 800064a..75fcf2e 100644 --- a/public/index.html +++ b/public/index.html @@ -60,5 +60,6 @@

{{ names[section] }}

+ diff --git a/public/js/frontend.js b/public/js/frontend.js index db8f2fd..2c7c084 100644 --- a/public/js/frontend.js +++ b/public/js/frontend.js @@ -79,7 +79,10 @@ $("#searchbar").keyup(function(e){ if(e.keyCode == 13){ term = this.value console.log(term) - doAjax("/search", "POST", searchHandler, {term: term}); + if (isValidURL(term)) + doAjax("/download", "POST", null, {url: term}); + else + doAjax("/search", "POST", searchHandler, {term: term}); } }) diff --git a/public/js/utils.js b/public/js/utils.js new file mode 100644 index 0000000..821a458 --- /dev/null +++ b/public/js/utils.js @@ -0,0 +1,8 @@ +function isValidURL(text){ + if (text.toLowerCase().startsWith("http")) + if (text.toLowerCase().indexOf("deezer.com") >= 0 || text.toLowerCase().indexOf("open.spotify.com") >= 0) + return true + else if (text.toLowerCase().startsWith("spotify:")) + return true + return false +}