1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
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) {
// swagger:route GET /share-link share-link
//
// Returns the share link
//
// This will return the share link for the currently running server,
// i.e. not 127.0.0.1 but a URL with (usually) an IPv4 RFC1918 address.
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Schemes:
// - http
//
// Deprecated: false
//
// Responses:
// 200: shareLinkResp
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)
}
}
// A shareLinkResp is an error that is used when the required input fails
// validation.
// swagger:response shareLinkResp
type shareLinkResp struct {
//
// in: body
Body struct {
// Example: http://10.0.0.99:8899/
URL string
}
}
func (a *App) HandleDeleteV1(w http.ResponseWriter, r *http.Request) {
// swagger:route DELETE /lib/game/{game} game
//
// Deletes a game
//
// Delete a given game where the url param game is the game in question
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Schemes: http, https
//
// Deprecated: false
//
// Responses:
// 200: ok
// 409: conflict
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)
}()
}
|