aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/index.go
blob: 2dfe20e3c4969538416d36613ded827d1b5b4ec5 (plain) (blame)
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
package main

import (
	"html/template"
	"net/http"

	"riedstra.dev/mitch/steam-export/steam"
)

var (
	Templ = template.Must(template.New("index").Parse(`
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <link id="maincss" rel="stylesheet" href="/style.css" defer>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Steam Game index</title>
</head>
<body>
<nav>
	<a href="/">Home</a>
	<div style="display: block; float: right;">
    <!-- <a href="">Right Aligned</a> -->
	</div>
</nav>

<h2>Library: {{.Lib.Folder}}</h2>

{{ if .Info.Running }}
<pre><code>
Currently Downloading from: {{.Info.Url}}
</pre></code>
{{ end }}

{{ if .Info.Error }}
<pre><code>
Error {{.Info.Error}} Downloading from: {{.Info.Url}}
{{ end }}
</pre></code>

<p>
Installed games:

Tip: You can right click and save link as to specify a save location, e.g.
an external hard drive
</p>

<ul>
{{ range $key, $val := .Lib.Games }}
<li>
<a href="/download/{{$key}}">{{$key}}</a>
</li>
{{ end }}
</ul>

Delete a game: ( Type out exact name, case sensitive )

<form action="/delete" method="POST">
  <input type="text" name="name" />
  <input type="submit" value="Delete">
</form>

Install a game from a URL or local file path:

<form action="/install" method="GET">
  <input type="text" name="uri" />
  <input type="submit" value="Install">
</form>

<p>
Note that You can also give someone a URL to install a game if they're running
this program, e.g. <br />
http://127.0.0.1:8899/install?uri=http://my-server-ip-or-hostname/download/My Game
</p>


</body>
`))
)

func index(w http.ResponseWriter, r *http.Request) {
	libMu.RLock()
	defer libMu.RUnlock()
	status.m.RLock()
	defer status.m.RUnlock()

	err := Templ.ExecuteTemplate(w, "index",
		struct {
			Lib  *steam.Library
			Info *statusInfo
		}{Lib, status.s})
	if err != nil {
		Logger.Printf("While Rendering template: %s", err)
	}
}