aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/handlers.go
diff options
context:
space:
mode:
authorMitchell <mitch@riedstra.dev>2021-03-20 01:37:03 -0400
committerMitchell <mitch@riedstra.dev>2021-03-20 01:37:03 -0400
commitd047c36dd09b6169bf27c244196e99bb5df54c3a (patch)
tree5103e1951bd58bbef54c90a13c199e8d1d866492 /cmd/web/handlers.go
parent0e62a3b46b25e7c101b14ed44235f3c276982fc0 (diff)
downloadsteam-export-d047c36dd09b6169bf27c244196e99bb5df54c3a.tar.gz
steam-export-d047c36dd09b6169bf27c244196e99bb5df54c3a.tar.xz
Update documentation. Remove all traces of chdir from the steam library. Remove most linter complaints.
Diffstat (limited to 'cmd/web/handlers.go')
-rw-r--r--cmd/web/handlers.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go
index b9b863a..661c411 100644
--- a/cmd/web/handlers.go
+++ b/cmd/web/handlers.go
@@ -14,6 +14,8 @@ import (
"riedstra.dev/mitch/steam-export/steam"
)
+// HandleIndex takes care of rendering our embedded template
+// and locks the steam library for each request.
func (a *App) HandleIndex(w http.ResponseWriter, r *http.Request) {
// During rendering of the template I believe it's
// mutating during the sort of keys, so Lib no longer
@@ -36,7 +38,7 @@ func (a *App) HandleIndex(w http.ResponseWriter, r *http.Request) {
&a.Library.Library,
a.Status,
isLocal(r.RemoteAddr),
- getHostIP(),
+ GetHostIP(),
getPort(),
Version,
})
@@ -46,6 +48,8 @@ func (a *App) HandleIndex(w http.ResponseWriter, r *http.Request) {
Logger.Printf("Client %s Index page", r.RemoteAddr)
}
+// HandleInstall takes the HTTP requests for installing a game from a URL
+// or local file path
func (a *App) HandleInstall(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
@@ -78,6 +82,7 @@ func (a *App) HandleInstall(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", 302)
}
+// HandleDownload takes care of exporting our games out to an HTTP request
func (a *App) HandleDownload(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
game := vars["game"]
@@ -129,6 +134,9 @@ func (a *App) HandleDownload(w http.ResponseWriter, r *http.Request) {
Logger.Printf("Client %s finished downloading: %s", r.RemoteAddr, game)
}
+// HandleDelete removes the game in question, though it doesn't
+// spawn any background processes it usually completes fast enough.
+// TODO: Fix if the request taking too long becomes an issue
func (a *App) HandleDelete(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
@@ -166,6 +174,8 @@ func (a *App) HandleDelete(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", 302)
}
+// HandleStats dumps out some internal statistics of installation which
+// is then parsed by some JS for a progress bar and such
func (a *App) HandleStats(w http.ResponseWriter, r *http.Request) {
a.Status.RLock()
defer a.Status.RUnlock()
@@ -181,6 +191,7 @@ func (a *App) HandleStats(w http.ResponseWriter, r *http.Request) {
return
}
+// HandleSetLib sets a new library path
func (a *App) HandleSetLib(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
@@ -194,6 +205,7 @@ func (a *App) HandleSetLib(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", 302)
}
+// HandleQuit just calls os.Exit after finishing the request
func HandleQuit(w http.ResponseWriter, r *http.Request) {
Logger.Println("Quit was called, exiting")
w.Header().Add("Content-type", "text/plain")