List of current work updates every second

testing
Justin Reichardt 2022-11-09 19:07:55 -06:00
parent 15f7c0c6e1
commit ba1bf0afde
1 changed files with 33 additions and 3 deletions

View File

@ -20,6 +20,7 @@
package main
import (
"encoding/json"
"io"
"io/ioutil"
"log"
@ -32,6 +33,7 @@ import (
)
const template = `
<!DOCTYPE html>
<html>
<head>
<title>Download</title>
@ -41,7 +43,26 @@ const template = `
<label>URL: <input name="URL" type="text""></label>
<input type="submit" value="Download">
</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>
</html>
`
@ -66,8 +87,17 @@ var opsc = make(chan ops)
// handleRequest handles http requests
func handleRequest(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
log.Print("New Get request")
if r.Method == http.MethodGet && r.URL.Path == "/currentwork" {
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 {
r.ParseForm()
go func() {