Moved distinction between URL and Search query to frontend

This commit is contained in:
RemixDev 2020-04-08 19:01:50 +02:00
parent c4d5624c37
commit 42264d0353
3 changed files with 13 additions and 1 deletions

View file

@ -60,5 +60,6 @@
</body>
<script type="text/javascript" src="/public/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/public/js/vue.min.js"></script>
<script type="text/javascript" src="/public/js/utils.js"></script>
<script type="text/javascript" src="/public/js/frontend.js"></script>
</html>

View file

@ -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});
}
})

8
public/js/utils.js Normal file
View file

@ -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
}