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 @@ <h1>{{ names[section] }}</h1>
</body> </body>
<script type="text/javascript" src="/public/js/jquery-3.3.1.min.js"></script> <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/vue.min.js"></script>
<script type="text/javascript" src="/public/js/utils.js"></script>
<script type="text/javascript" src="/public/js/frontend.js"></script> <script type="text/javascript" src="/public/js/frontend.js"></script>
</html> </html>

View File

@ -79,7 +79,10 @@ $("#searchbar").keyup(function(e){
if(e.keyCode == 13){ if(e.keyCode == 13){
term = this.value term = this.value
console.log(term) 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
}