Use env variables for RPC auth

This commit is contained in:
Jeffrey Serio 2023-03-25 17:33:51 -05:00
parent 34f1a53f73
commit 90bc1df230
3 changed files with 5 additions and 20 deletions

View File

@ -8,7 +8,7 @@ For other people using this, change the stylesheet in `template.html` to your pr
transmissionbt, err := transmissionrpc.New("<your Transmission server ip>", "username", "password", nil)
```
My personal use case for this involves running the Go binary `go-transmission-stats` on a systemd timer that triggers the corresponding service every 12 hours. The systemd service looks like this:
My personal use case for this involves running the Go binary `go-transmission-stats` on a systemd timer that triggers the corresponding service every 12 hours.
First build the binary:

View File

@ -79,7 +79,7 @@ type TorrentStatsPageData struct {
}
func main() {
transmissionbt, err := transmissionrpc.New("", "", "", nil)
transmissionbt, err := transmissionrpc.New(os.Getenv("RPC_HOST"), os.Getenv("RPC_USER"), os.Getenv("RPC_PASSWD"), nil)
if err != nil {
panic(err)
}
@ -103,7 +103,7 @@ func main() {
{Label: "Uploaded/Downloaded ratio", Value: fmt.Sprintf("%d", *&stats.CurrentStats.UploadedBytes / *&stats.CurrentStats.DownloadedBytes)},
{Label: "Files added", Value: fmt.Sprintf("%d", *&stats.CurrentStats.FilesAdded)},
{Label: "Session count", Value: fmt.Sprintf("%d", *&stats.CurrentStats.SessionCount)},
{Label: "Seconds active", Value: convertTime(*&stats.CurrentStats.SecondsActive)},
{Label: "Time active", Value: convertTime(*&stats.CurrentStats.SecondsActive)},
}
cumulativeStats := []SessionStat{
@ -112,7 +112,7 @@ func main() {
{Label: "Uploaded/Downloaded ratio", Value: fmt.Sprintf("%d", *&stats.CumulativeStats.UploadedBytes / *&stats.CumulativeStats.DownloadedBytes)},
{Label: "Files added", Value: fmt.Sprintf("%d", *&stats.CumulativeStats.FilesAdded)},
{Label: "Session count", Value: fmt.Sprintf("%d", *&stats.CumulativeStats.SessionCount)},
{Label: "Seconds active", Value: convertTime(*&stats.CumulativeStats.SecondsActive)},
{Label: "Time active", Value: convertTime(*&stats.CumulativeStats.SecondsActive)},
}
var torrentInfo = []TorrentInfo{}

View File

@ -5,22 +5,7 @@
<link rel="icon" type="image/x-icon" href="coffee.svg">
<link href="catppuccin.css" rel="stylesheet">
</head>
<style>
table, th, td {
border:1px solid #7f849c;
border-collapse: collapse;
padding: 10px;
}
table {
margin-top: 24px;
}
.name {
color: #a6e3a1;
}
.container {
margin-bottom: 64px;
}
</style>
<body>
<div class="container">
<h1>Torrent Stats</h1>