update(front): show how many tracks have been done

This commit is contained in:
rick 2021-08-31 18:39:56 +02:00
parent 7ee7676d6d
commit 1e292688c6
Signed by: Rick
GPG key ID: 2B593F087240EE99
2 changed files with 36 additions and 9 deletions

View file

@ -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"`
}
@ -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) {

View file

@ -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,8 +21,13 @@
<script>
async function test() {
const data = await fetch('/refresh').then(response => response.json());
console.log(data.url);
if (data != null) {
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");
@ -24,11 +35,16 @@
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>