diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2021-08-24 22:25:40 -0400 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2021-08-24 22:25:40 -0400 |
| commit | 0fc3eda77004f41c5f0a804028da2d90b0373ea7 (patch) | |
| tree | edf6d74e6a2b7140350eab1e40d0fbf70e10f87c /cmd/web/handlers.go | |
| parent | f4fcd237b2d0eb950fc15a8af1fb0894b6ad6359 (diff) | |
| download | steam-export-0fc3eda77004f41c5f0a804028da2d90b0373ea7.tar.gz steam-export-0fc3eda77004f41c5f0a804028da2d90b0373ea7.tar.xz | |
Another development snapshot. Updated license. Added Swagger documentation--embedded! Note about 'swaggo'
Diffstat (limited to 'cmd/web/handlers.go')
| -rw-r--r-- | cmd/web/handlers.go | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index e61c29d..06d699c 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -5,14 +5,11 @@ import ( "fmt" "html/template" "net/http" - "os" - "time" "github.com/gorilla/mux" ) -// HandleIndex takes care of rendering our embedded template -// and locks the steam library for each request. +// HandleIndex takes care of rendering our embedded template out to the client func (a *App) HandleIndex(w http.ResponseWriter, r *http.Request) { t, err := template.ParseFS(a.templateFS, "templates/index.html") if err != nil { @@ -62,6 +59,17 @@ func (a *App) HandleInstall(w http.ResponseWriter, r *http.Request) { } // HandleDownload takes care of exporting our games out to an HTTP request +// +// @Summary Handles downloading of a game +// @Description Streams a tarball of the game including the ACF file down +// @Description to the client machine +// @Tags all, game +// @Param game path string true "Name of the videogame" +// @Header 200 {string} Estimated-size "Estimated game size in bytes" +// @Accept json +// @Produce application/tar +// @Success 200 +// @Router /lib/game/{game} [get] func (a *App) HandleDownload(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) game := vars["game"] @@ -99,7 +107,7 @@ func (a *App) HandleDelete(w http.ResponseWriter, r *http.Request) { game := r.PostForm.Get("name") if game == "" { - Logger.Println("Deleter: No game specified") + Logger.Println("Delete: No game specified") http.Error(w, "Game param required", 400) return } @@ -124,18 +132,20 @@ func (a *App) HandleDelete(w http.ResponseWriter, r *http.Request) { // 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) { - w.Header().Add("Content-type", "application/json") +func (a *App) HandleStats() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-type", "application/json") - enc := json.NewEncoder(w) + enc := json.NewEncoder(w) - enc.SetIndent("", " ") + enc.SetIndent("", " ") - err := enc.Encode(a.Library.Status()) - if err != nil { - Logger.Println("While encoding Status: ", err) - } - return + err := enc.Encode(a.Library.Status()) + if err != nil { + Logger.Println("While encoding Status: ", err) + } + return + }) } // HandleSetLib sets a new library path @@ -151,15 +161,3 @@ 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") - w.Write([]byte("Shutting down... feel free to close this")) - go func() { - time.Sleep(time.Millisecond * 50) - os.Exit(0) - }() - return -} |
