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
|
package main
import (
"net/http"
"github.com/gorilla/mux"
httpSwagger "github.com/swaggo/http-swagger"
_ "riedstra.dev/mitch/steam-export/cmd/web/docs"
)
func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
rtr := mux.NewRouter()
rtr.PathPrefix("/swagger").Methods("GET").Handler(
httpSwagger.Handler(
//The url pointing to API definition
httpSwagger.URL("/swagger/doc.json"),
httpSwagger.DeepLinking(true),
httpSwagger.DocExpansion("none"),
httpSwagger.DomID("#swagger-ui"),
))
rtr.PathPrefix("/api/v1").Handler(
http.StripPrefix("/api/v1", a.HandleAPIv1()))
rtr.Handle("/quit", UnauthorizedIfNotLocal(http.HandlerFunc(HandleQuit)))
rtr.Handle("/setLib", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleSetLib)))
rtr.Handle("/delete", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleDelete)))
rtr.Handle("/install", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleInstall)))
rtr.Handle("/status", UnauthorizedIfNotLocal(a.HandleStats()))
rtr.Handle("/steam-export-web.exe", HandleSelfServe())
rtr.HandleFunc("/download/{game}", a.HandleDownload)
rtr.PathPrefix("/static").Handler(
http.FileServer(http.FS(a.staticFS)))
rtr.HandleFunc("/", a.HandleIndex)
rtr.ServeHTTP(w, r)
}
func (a *App) HandleAPIv1() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rtr := mux.NewRouter()
rtr.Handle("/quit", UnauthorizedIfNotLocal(http.HandlerFunc(HandleQuit)))
rtr.Handle("/status", a.HandleStats())
rtr.Handle("/share-link", http.HandlerFunc(a.HandleShareLink))
rtr.Handle("/version", http.HandlerFunc(a.HandleVersion))
rtr.Path("/lib/games").Methods("GET").HandlerFunc(a.HandleGameList)
rtr.Path("/lib/game/{game}").Methods("GET").HandlerFunc(a.HandleDownload)
rtr.Path("/lib/game/{game}").Methods("DELETE").Handler(
UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleDeleteV1)))
rtr.Path("/lib/refresh").Methods("GET", "POST").Handler(
UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleRefresh)))
rtr.Path("/lib/path").Methods("POST").Handler(
UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleSetLibV1)))
rtr.Path("/lib/install").Methods("POST").Handler(
UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleInstallV1)))
rtr.ServeHTTP(w, r)
})
}
|