List of current work updates every second
parent
15f7c0c6e1
commit
ba1bf0afde
|
|
@ -20,6 +20,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
|
@ -32,6 +33,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const template = `
|
const template = `
|
||||||
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Download</title>
|
<title>Download</title>
|
||||||
|
|
@ -41,7 +43,26 @@ const template = `
|
||||||
<label>URL: <input name="URL" type="text""></label>
|
<label>URL: <input name="URL" type="text""></label>
|
||||||
<input type="submit" value="Download">
|
<input type="submit" value="Download">
|
||||||
</form>
|
</form>
|
||||||
<p>currentWork</p>
|
<script>
|
||||||
|
setInterval(()=>{
|
||||||
|
fetch("currentwork").then(response => {
|
||||||
|
if (!response.ok){
|
||||||
|
throw new Error("HTTP error " + response.status);
|
||||||
|
}
|
||||||
|
return response.text();
|
||||||
|
}).then(json => {
|
||||||
|
parsed = JSON.parse(json)
|
||||||
|
console.log(parsed);
|
||||||
|
Object.entries(parsed).forEach(([key, value]) => {document.getElementById("list").innerText += value});
|
||||||
|
if (json === "{}"){
|
||||||
|
}
|
||||||
|
}).catch( () => {
|
||||||
|
console.log("Error retrieving setup status");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
, 1000);
|
||||||
|
</script>
|
||||||
|
<p id=list></p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`
|
`
|
||||||
|
|
@ -66,8 +87,17 @@ var opsc = make(chan ops)
|
||||||
|
|
||||||
// handleRequest handles http requests
|
// handleRequest handles http requests
|
||||||
func handleRequest(w http.ResponseWriter, r *http.Request) {
|
func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == http.MethodGet {
|
if r.Method == http.MethodGet && r.URL.Path == "/currentwork" {
|
||||||
log.Print("New Get request")
|
list, err := json.Marshal(currentWork)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write(list)
|
||||||
|
return
|
||||||
|
|
||||||
|
} else if r.Method == http.MethodGet {
|
||||||
|
log.Print("New Get request: " + r.URL.Path)
|
||||||
} else if r.Method == http.MethodPost {
|
} else if r.Method == http.MethodPost {
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue