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
180
181
182
183
|
package main
import (
"fmt"
"net/http"
"time"
"github.com/gorilla/mux"
"riedstra.dev/mitch/steam-export/steam"
)
// @Summary Return share link
// @Description The URL returned is a best effort guess at what your internal
// @Description network IP is, on Windows this involves automatically using
// @Description the IP from the interface associated with your default route.
// @Description On other platforms this involves simply returning the first
// @Description sane looking IP address with no regard for anything else.
// @Tags all, information
// @Accept json
// @Produce json
// @Success 200 {string} string "URL to currently running server"
// @Router /share-link [get]
func (a *App) HandleShareLink(w http.ResponseWriter, r *http.Request) {
HttpJSONResp(w, r, http.StatusOK, "", a.ShareLink)
}
// @Summary Delete a videogame
// @Description Handle deletion of a game
// @Tags all, game
// @param game path string true "Name of the videogame"
// @Accept json
// @Produce json
// @Success 200 {object} respStatus "Game was deleted"
// @Failure 400 {object} respError "Bad request, most likely no game supplied"
// @Failure 404 {object} respError "Game not found"
// @Failure 409 {object} respError "Another operation is currently running"
// @Failure 500 {object} respError
// @Router /lib/game/{game} [delete]
func (a *App) HandleDeleteV1(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
game, ok := vars["game"]
if !ok {
HttpJSONRespErr(w, r, http.StatusBadRequest,
"No game supplied", "No game supplied")
return
}
g, ok := a.Library.Games()[game]
if !ok {
HttpJSONRespErr(w, r, http.StatusNotFound,
fmt.Sprintf("missing game: %s", game),
"Game is missing")
return
}
// TODO: Check and see if there is another operation running
// for this game and return an appropriate message
err := a.Library.Delete(g.Name)
if err != nil {
HttpJSONRespErr(w, r, http.StatusInternalServerError,
fmt.Sprintf("Error removing game: %s", err),
fmt.Sprintf("Error removing game: %s", err))
return
}
HttpJSONOK(w, r, fmt.Sprintf("Deleted game %s", game))
}
// @Summary Get available games
// @Description Returns a list of all currently installed and available games
// @Tags all, game
// @Accept json
// @Produce json
// @Success 200 {array} steam.Game
// @Router /lib/games [get]
func (a *App) HandleGameList(w http.ResponseWriter, r *http.Request) {
games := a.Library.Games()
out := []*steam.Game{}
for _, g := range games {
out = append(out, g)
}
HttpJSONResp(w, r, http.StatusOK, "", &out)
}
// @Summary Return the version string
// @Description Returns the version of the server
// @Tags all
// @Accept json
// @Produce json
// @Success 200 {string} string "Version string"
// @Router /version [get]
func (a *App) HandleVersion(w http.ResponseWriter, r *http.Request) {
HttpJSONResp(w, r, http.StatusOK, "", Version)
}
// @Summary Refresh the current steam library
// @Description if no other actions are running on the library it will trigger a
// @Description refre
// @Tags all, library
// @Accept json
// @Produce json
// @Success 200 {object} respStatus
// @Success 500 {object} respError
// @Router /lib/refresh [post]
func (a *App) HandleRefresh(w http.ResponseWriter, r *http.Request) {
err := a.Library.Refresh()
if err != nil {
HttpJSONRespErr(w, r, http.StatusInternalServerError,
fmt.Sprintf("While refreshing library: %s", err),
fmt.Sprintf("Error refreshing library, check logs"))
return
}
HttpJSONOK(w, r, "Refreshed library")
}
// @Summary Set library path to new location on disk
// @Description If no other operatoins are currently running this will change
// @Description the path in which the current library is pointed. Implies a
// @Description refresh.
// @param path query string true "Path on disk to search for a steam library"
// @Tags all, library
// @Accept json
// @Produce json
// @Success 200 {object} respStatus
// @Success 500 {object} respError
// @Router /lib/path [post]
func (a *App) HandleSetLibV1(w http.ResponseWriter, r *http.Request) {
pth := r.URL.Query().Get("path")
err := a.Library.ProcessLibrary(pth)
if err != nil {
HttpJSONRespErr(w, r, http.StatusInternalServerError,
fmt.Sprintf("While processing library: ", err),
"Internal server error")
return
}
HttpJSONOK(w, r, "Set and Refreshed library")
}
// @Summary Installs a game
// @Description Attemps to install a game from the provided URI
// @Description It tries to be smart about it, http, https, or a location
// @Description on disk are supported.
// @param url query string true "URI to fetch from"
// @Tags all, game
// @Accept json
// @Produce json
// @Success 200 {object} respStatus
// @Success 500 {object} respError
// @Router /lib/install [post]
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")
// We're not going to block for the entire install, but we will wait around
// for a small bit to see if there are any major failures
go func() {
var g *steam.Game
g, err = a.Library.ExtractSmart(url)
if err != nil {
Logger.Printf("Error encountered installing: %s", err)
}
Logger.Printf("Extracted game: %s", g)
}()
time.Sleep(time.Millisecond * 50)
if err != nil {
HttpJSONRespErr(w, r, http.StatusInternalServerError,
"",
fmt.Sprintf("Failed to start game install: %s", err))
return
}
HttpJSONOK(w, r, "")
}
|