aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/install.go
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2021-01-09 00:49:16 -0500
committerMitch Riedstra <mitch@riedstra.us>2021-01-09 00:49:16 -0500
commite31c9168627c040317e5cc8566724f88910439ae (patch)
tree0ce4b3de81adfe8f9af56c498a969a8a2be44280 /cmd/web/install.go
parentd762cdbae06efd194ffac7b976c16aac21a26f94 (diff)
downloadsteam-export-e31c9168627c040317e5cc8566724f88910439ae.tar.gz
steam-export-e31c9168627c040317e5cc8566724f88910439ae.tar.xz
Add some download stats, and a status endpoint.
Diffstat (limited to 'cmd/web/install.go')
-rw-r--r--cmd/web/install.go31
1 files changed, 25 insertions, 6 deletions
diff --git a/cmd/web/install.go b/cmd/web/install.go
index 63faaf6..678037a 100644
--- a/cmd/web/install.go
+++ b/cmd/web/install.go
@@ -1,18 +1,23 @@
package main
import (
+ "encoding/json"
+ "fmt"
+ "net/http"
"net/url"
"os"
"strings"
- "fmt"
- "net/http"
"sync"
+ "time"
)
type statusInfo struct {
- Running bool
- Error error
- Url string
+ Running bool
+ Error error
+ Url string
+ Transferred int64
+ Size int64
+ Start *time.Time
}
var (
@@ -27,6 +32,19 @@ var (
getPath = make(chan string)
)
+func statsHandler(w http.ResponseWriter, r *http.Request) {
+ status.m.RLock()
+ defer status.m.RUnlock()
+
+ enc := json.NewEncoder(w)
+
+ err := enc.Encode(status.s)
+ if err != nil {
+ Logger.Println("While encoding status: ", err)
+ }
+ return
+}
+
func installHttp(u string) error {
Logger.Println("Installer: loading from url")
resp, err := http.Get(u)
@@ -57,6 +75,8 @@ func installPath(p string) error {
return nil
}
+// installer handles installing games either from a local path or a
+// remote URL
func installer(urls <-chan string) {
var err error
for u := range urls {
@@ -87,7 +107,6 @@ func gameInstaller(w http.ResponseWriter, r *http.Request) {
return
}
-
err := r.ParseForm()
if err != nil {
Logger.Printf("Installer: While parsing form: %s", err)