aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2020-11-21 16:44:48 -0500
committerMitch Riedstra <mitch@riedstra.us>2020-11-21 16:44:48 -0500
commit3e1b39031437eaf48c5c6ea895dd632b1249b0a2 (patch)
tree3b778d03d074b3798a4c53bbf19b1b0be389260d
parent415c4a1a48502ae5180c48188c8f2e94d9c9d92c (diff)
downloadsteam-export-3e1b39031437eaf48c5c6ea895dd632b1249b0a2.tar.gz
steam-export-3e1b39031437eaf48c5c6ea895dd632b1249b0a2.tar.xz
Allow the library to be changed. Fix up quit handler. Improve logging
-rw-r--r--cmd/web/delete.go1
-rw-r--r--cmd/web/download.go6
-rw-r--r--cmd/web/index.go8
-rw-r--r--cmd/web/install.go5
-rw-r--r--cmd/web/main.go27
-rw-r--r--cmd/web/windows.go2
6 files changed, 44 insertions, 5 deletions
diff --git a/cmd/web/delete.go b/cmd/web/delete.go
index 7188b45..5bf747e 100644
--- a/cmd/web/delete.go
+++ b/cmd/web/delete.go
@@ -36,6 +36,7 @@ func gameDelete(w http.ResponseWriter, r *http.Request) {
http.Error(w, fmt.Sprintf("Error removing game: %s", err), 500)
return
}
+ Logger.Printf("Removed game: %s", game)
reloadLib()
http.Redirect(w, r, "/", 302)
diff --git a/cmd/web/download.go b/cmd/web/download.go
index a640ea2..93c4ff5 100644
--- a/cmd/web/download.go
+++ b/cmd/web/download.go
@@ -21,11 +21,13 @@ func gameDownloader(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-type", "application/tar")
+ Logger.Printf("Client %s is downloading: %s", r.RemoteAddr, game)
err := g.Package(w)
if err != nil {
- Logger.Printf("Error Sending game: %s", err)
+ Logger.Printf("Client %s Error Sending game: %s", r.RemoteAddr, err)
// Headers already sent, don't bother sending an error
+ return
}
-
+ Logger.Printf("Client %s finished downloading: %s", r.RemoteAddr, game)
}
diff --git a/cmd/web/index.go b/cmd/web/index.go
index 59310c0..2eb3695 100644
--- a/cmd/web/index.go
+++ b/cmd/web/index.go
@@ -75,6 +75,13 @@ http://127.0.0.1:8899/install?uri=http://my-server-ip-or-hostname/download/My Ga
</p>
+Change library path
+<form action="/setLib" method="GET">
+ <input type="text" name="path" />
+ <input type="submit" value="Update">
+</form>
+
+
</body>
`))
)
@@ -93,4 +100,5 @@ func index(w http.ResponseWriter, r *http.Request) {
if err != nil {
Logger.Printf("While Rendering template: %s", err)
}
+ Logger.Printf("Client %s Index page", r.RemoteAddr)
}
diff --git a/cmd/web/install.go b/cmd/web/install.go
index cd2f03a..aae4191 100644
--- a/cmd/web/install.go
+++ b/cmd/web/install.go
@@ -28,6 +28,7 @@ var (
)
func installHttp(u string) error {
+ Logger.Println("Installer: loading from url")
resp, err := http.Get(u)
if err != nil {
return fmt.Errorf("Installer: getting %w", err)
@@ -42,6 +43,7 @@ func installHttp(u string) error {
}
func installPath(p string) error {
+ Logger.Println("Installer: loading from filesystem")
fh, err := os.Open(p)
if err != nil {
return fmt.Errorf("Installer: opening %w", err)
@@ -59,6 +61,7 @@ func installer(urls <-chan string) {
var err error
for u := range urls {
status.m.Lock()
+ Logger.Printf("Installer: running for URI: %s", u)
status.s.Running = true
status.s.Url = u
status.m.Unlock()
@@ -72,6 +75,7 @@ func installer(urls <-chan string) {
status.m.Lock()
status.s.Running = false
status.s.Error = err
+ Logger.Printf("Installer: Completed request %s Errors: %s", u, err)
status.m.Unlock()
reloadLib()
@@ -110,6 +114,7 @@ func gameInstaller(w http.ResponseWriter, r *http.Request) {
}
}
+ Logger.Printf("Installer: Sending request for: %s to channel", uri)
getPath <- uri
http.Redirect(w, r, "/", 302)
diff --git a/cmd/web/main.go b/cmd/web/main.go
index f5365d0..6bf0a5d 100644
--- a/cmd/web/main.go
+++ b/cmd/web/main.go
@@ -23,19 +23,41 @@ var (
)
func reloadLib() {
+ Logger.Println("Starting library reload")
libMu.Lock()
defer libMu.Unlock()
var err error
- Lib, err = steam.NewLibrary(DefaultLib)
+ l2, err := steam.NewLibrary(DefaultLib)
if err != nil {
Logger.Printf("Error reopening library: %s", err)
return
}
+ Lib = l2
+ Logger.Println("Done reloading library")
+}
+
+func setLibHandler(w http.ResponseWriter, r *http.Request) {
+ err := r.ParseForm()
+ if err != nil {
+ Logger.Printf("Setlib: While parsing form: %s", err)
+ http.Error(w, fmt.Sprintf("Invalid form: %s", err), 400)
+ return
+ }
+
+ DefaultLib = r.Form.Get("path")
+ reloadLib()
+ http.Redirect(w, r, "/", 302)
}
func quitHandler(w http.ResponseWriter, r *http.Request) {
Logger.Println("Quit was called, exiting")
- os.Exit(0)
+ w.Header().Add("Content-type", "text/plain")
+ w.Write([]byte("Shutting down..."))
+ go func() {
+ time.Sleep(time.Second*2)
+ os.Exit(0)
+ }()
+ return
}
func main() {
@@ -60,6 +82,7 @@ func main() {
r := mux.NewRouter()
r.HandleFunc("/quit", quitHandler)
+ r.HandleFunc("/setLib", setLibHandler)
r.HandleFunc("/delete", gameDelete)
r.HandleFunc("/install", gameInstaller)
r.HandleFunc("/download/{game}", gameDownloader)
diff --git a/cmd/web/windows.go b/cmd/web/windows.go
index 9fe8ab6..034e347 100644
--- a/cmd/web/windows.go
+++ b/cmd/web/windows.go
@@ -12,6 +12,6 @@ var DefaultLib string = `C:\Program Files (x86)\Steam\steamapps`
func startBrowser() {
time.Sleep(time.Second*3)
c := exec.Command("cmd", "/c", "start", "http://127.0.0.1"+Listen)
- Logger.Println(c.Run())
+ Logger.Printf("Running command: %s", c.Run())
}