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
13
server.go
13
server.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
"strings"
|
"strings"
|
||||||
"net/http"
|
"net/http"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -15,6 +16,8 @@ type BandcampAlbum struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RespBandcamp struct {
|
type RespBandcamp struct {
|
||||||
|
Done int `json:"done"`
|
||||||
|
Todo int `json:"todo"`
|
||||||
Url []string `json:"url"`
|
Url []string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +85,8 @@ func getListPlaylist(id string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp := BandcampAlbum{}
|
tmp := BandcampAlbum{}
|
||||||
|
MyResp.Todo = len(ree.Items)
|
||||||
|
MyResp.Done = 0
|
||||||
|
|
||||||
for i := 0; i < len(ree.Items); i++ {
|
for i := 0; i < len(ree.Items); i++ {
|
||||||
tmp = testBandcamp(ree.Items[i].Track.Album.Name,
|
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("tmp %s \n", MyResp.url[0])
|
||||||
//fmt.Printf("len=%d cap=%d %v\n", len(MyResp.url), cap(MyResp.url), MyResp.url)
|
//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) {
|
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.Header().Set("Location", "/tmp.html")
|
||||||
w.WriteHeader(http.StatusSeeOther)
|
w.WriteHeader(http.StatusSeeOther)
|
||||||
go getListPlaylist("6OGZZ8tI45MB1d3EUEqNKI")
|
//go getListPlaylist("6OGZZ8tI45MB1d3EUEqNKI")
|
||||||
|
go getListPlaylist(r.FormValue("id"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func index(w http.ResponseWriter, r *http.Request) {
|
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>
|
<p>Recherche dans une playlist les artistes se trouvant aussi sur Bandcamp !</p>
|
||||||
<hr />
|
<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 id="my-list">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -15,8 +21,13 @@
|
||||||
<script>
|
<script>
|
||||||
async function test() {
|
async function test() {
|
||||||
const data = await fetch('/refresh').then(response => response.json());
|
const data = await fetch('/refresh').then(response => response.json());
|
||||||
console.log(data.url);
|
|
||||||
if (data != null) {
|
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) {
|
for (const elem of data.url) {
|
||||||
let tmp = document.createTextNode(elem);
|
let tmp = document.createTextNode(elem);
|
||||||
let newP = document.createElement("p");
|
let newP = document.createElement("p");
|
||||||
|
@ -24,11 +35,16 @@
|
||||||
document.getElementById("my-list").appendChild(newP);
|
document.getElementById("my-list").appendChild(newP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.getElementById("nb-fait").textContent = data.done;
|
||||||
|
document.getElementById("nb-total").textContent = data.todo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
window.onbeforeunload = function() {
|
||||||
return "Vous perdrez tous les artistes trouvés en rafraichissant la page."
|
return "Vous perdrez tous les artistes trouvés en rafraichissant la page."
|
||||||
}
|
}
|
||||||
setInterval(test, 3000);
|
|
||||||
|
const refreshList = setInterval(test, 3000);
|
||||||
</script>
|
</script>
|
||||||
<html>
|
<html>
|
||||||
|
|
Loading…
Reference in a new issue