update(front): show how many tracks have been done
This commit is contained in:
parent
7ee7676d6d
commit
1e292688c6
2 changed files with 36 additions and 9 deletions
15
server.go
15
server.go
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
"strings"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
|
@ -15,6 +16,8 @@ type BandcampAlbum struct {
|
|||
}
|
||||
|
||||
type RespBandcamp struct {
|
||||
Done int `json:"done"`
|
||||
Todo int `json:"todo"`
|
||||
Url []string `json:"url"`
|
||||
}
|
||||
|
||||
|
@ -54,7 +57,7 @@ func getListPlaylist(id string) {
|
|||
req, _ := http.NewRequest("GET",
|
||||
"https://api.spotify.com/v1/playlists/"+id+"/tracks",
|
||||
nil)
|
||||
*/
|
||||
*/
|
||||
req, _ := http.NewRequest("GET",
|
||||
"http://localhost:8001",
|
||||
nil)
|
||||
|
@ -82,6 +85,8 @@ func getListPlaylist(id string) {
|
|||
}
|
||||
|
||||
tmp := BandcampAlbum{}
|
||||
MyResp.Todo = len(ree.Items)
|
||||
MyResp.Done = 0
|
||||
|
||||
for i := 0; i < len(ree.Items); i++ {
|
||||
tmp = testBandcamp(ree.Items[i].Track.Album.Name,
|
||||
|
@ -94,7 +99,12 @@ func getListPlaylist(id string) {
|
|||
//fmt.Printf("tmp %s \n", MyResp.url[0])
|
||||
//fmt.Printf("len=%d cap=%d %v\n", len(MyResp.url), cap(MyResp.url), MyResp.url)
|
||||
}
|
||||
if i % 25 == 0 {
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
MyResp.Done++
|
||||
}
|
||||
fmt.Printf("\nFinish\n")
|
||||
}
|
||||
|
||||
func formHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -112,7 +122,8 @@ func formHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
w.Header().Set("Location", "/tmp.html")
|
||||
w.WriteHeader(http.StatusSeeOther)
|
||||
go getListPlaylist("6OGZZ8tI45MB1d3EUEqNKI")
|
||||
//go getListPlaylist("6OGZZ8tI45MB1d3EUEqNKI")
|
||||
go getListPlaylist(r.FormValue("id"))
|
||||
}
|
||||
|
||||
func index(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
@ -8,6 +8,12 @@
|
|||
<p>Recherche dans une playlist les artistes se trouvant aussi sur Bandcamp !</p>
|
||||
<hr />
|
||||
|
||||
<div id="inf-loader">
|
||||
<div id="loader"></div>
|
||||
<p>La playlist est en cours de traitement [<span id="nb-fait"></span>/<span id="nb-total"></span>]…</p>
|
||||
<p>[Code Source du loader](https://codepen.io/brunjo/pen/bNEWjV) sous [licence MIT](https://blog.codepen.io/documentation/licensing/).</p>
|
||||
</div>
|
||||
|
||||
<div id="my-list">
|
||||
|
||||
</div>
|
||||
|
@ -15,20 +21,30 @@
|
|||
<script>
|
||||
async function test() {
|
||||
const data = await fetch('/refresh').then(response => response.json());
|
||||
console.log(data.url);
|
||||
if (data != null) {
|
||||
for (const elem of data.url) {
|
||||
let tmp = document.createTextNode(elem);
|
||||
let newP = document.createElement("p");
|
||||
newP.appendChild(tmp);
|
||||
document.getElementById("my-list").appendChild(newP);
|
||||
if (data.done === data.todo) {
|
||||
document.getElementById("inf-loader").remove();
|
||||
clearInterval(refreshList);
|
||||
}
|
||||
|
||||
if (data.url != null) {
|
||||
for (const elem of data.url) {
|
||||
let tmp = document.createTextNode(elem);
|
||||
let newP = document.createElement("p");
|
||||
newP.appendChild(tmp);
|
||||
document.getElementById("my-list").appendChild(newP);
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById("nb-fait").textContent = data.done;
|
||||
document.getElementById("nb-total").textContent = data.todo;
|
||||
}
|
||||
}
|
||||
|
||||
window.onbeforeunload = function() {
|
||||
return "Vous perdrez tous les artistes trouvés en rafraichissant la page."
|
||||
}
|
||||
setInterval(test, 3000);
|
||||
|
||||
const refreshList = setInterval(test, 3000);
|
||||
</script>
|
||||
<html>
|
||||
|
|
Loading…
Reference in a new issue