package main import ( "encoding/json" "fmt" "net/http" "github.com/gorilla/mux" "riedstra.dev/mitch/steam-export/steam" ) func (a *App) HandleShareLink(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-type", "application/json") enc := json.NewEncoder(w) err := enc.Encode(a.ShareLink) if err != nil { Logger.Println("While getting shareLink: ", err) } } func (a *App) HandleDeleteV1(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) game, ok := vars["game"] if !ok { Logger.Println("No game supplied for HandleDeleteV1") http.Error(w, "No game supplied", http.StatusBadRequest) return } g, ok := a.Library.Games()[game] if !ok { Logger.Printf("Missing: %s", game) http.Error(w, "Game is missing", 404) return } err := a.Library.Delete(g.Name) if err != nil { Logger.Printf("Error removing game: %s", err) http.Error(w, fmt.Sprintf("Error removing game: %s", err), 500) return } Logger.Printf("Removed game: %s", game) http.Redirect(w, r, "/", 302) } func (a *App) HandleGameList(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-type", "application/json") enc := json.NewEncoder(w) games := a.Library.Games() out := []*steam.Game{} for _, g := range games { out = append(out, g) } err := enc.Encode(&out) if err != nil { Logger.Println("While getting games: ", err) } } func (a *App) HandleVersion(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-type", "application/json") enc := json.NewEncoder(w) err := enc.Encode(Version) if err != nil { Logger.Println("While getting version: ", err) } } func (a *App) HandleRefresh(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-type", "application/json") err := a.Library.Refresh() if err != nil { Logger.Println("While refreshing steam lib: ", err) } enc := json.NewEncoder(w) enc.Encode(map[string]interface{}{ "status": "ok", }) } func (a *App) HandleSetLibV1(w http.ResponseWriter, r *http.Request) { out := map[string]interface{}{} w.Header().Add("Content-type", "application/json") pth := r.URL.Query().Get("path") err := a.Library.ProcessLibrary(pth) if err != nil { Logger.Println("While processing library: ", err) out["error"] = err.Error() out["status"] = "error" } else { out["status"] = "ok" } enc := json.NewEncoder(w) enc.Encode(out) } func (a *App) HandleInstallV1(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-type", "application/json") var err error url := r.URL.Query().Get("url") go func() { var g *steam.Game g, err = a.Library.ExtractSmart(url) if err != nil { Logger.Printf("Error encountered installing: %s", err) } Logger.Printf("Extrated game: %s", g) }() }