Add about page
This commit is contained in:
parent
3101d1941c
commit
b139195437
8 changed files with 128 additions and 15 deletions
1
go.mod
1
go.mod
|
|
@ -5,6 +5,7 @@ go 1.23
|
||||||
require (
|
require (
|
||||||
github.com/dustin/go-humanize v1.0.1
|
github.com/dustin/go-humanize v1.0.1
|
||||||
github.com/go-chi/chi/v5 v5.1.0
|
github.com/go-chi/chi/v5 v5.1.0
|
||||||
|
github.com/matishsiao/goInfo v0.0.0-20240924010139-10388a85396f
|
||||||
github.com/rs/zerolog v1.33.0
|
github.com/rs/zerolog v1.33.0
|
||||||
golang.org/x/sync v0.10.0
|
golang.org/x/sync v0.10.0
|
||||||
)
|
)
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -4,6 +4,8 @@ github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+m
|
||||||
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
|
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
|
||||||
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
|
github.com/matishsiao/goInfo v0.0.0-20240924010139-10388a85396f h1:XDrsC/9hdgiU9ecceSmYsS2E3fBtFiYc34dAMFgegnM=
|
||||||
|
github.com/matishsiao/goInfo v0.0.0-20240924010139-10388a85396f/go.mod h1:aEt7p9Rvh67BYApmZwNDPpgircTO2kgdmDUoF/1QmwA=
|
||||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ func main() {
|
||||||
router.Get("/fetch", media.FetchMedia)
|
router.Get("/fetch", media.FetchMedia)
|
||||||
router.Get("/api/download", media.FetchMediaApi)
|
router.Get("/api/download", media.FetchMediaApi)
|
||||||
router.Get("/download", media.ServeMedia)
|
router.Get("/download", media.ServeMedia)
|
||||||
|
router.Get("/about", media.AboutIndex)
|
||||||
})
|
})
|
||||||
fileServer(router, "/static", "static/")
|
fileServer(router, "/static", "static/")
|
||||||
|
|
||||||
|
|
|
||||||
42
src/media/about.go
Normal file
42
src/media/about.go
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
package media
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/matishsiao/goInfo"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"html/template"
|
||||||
|
"media-roller/src/utils"
|
||||||
|
"net/http"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var aboutIndexTmpl = template.Must(template.ParseFiles("templates/media/about.html"))
|
||||||
|
|
||||||
|
var newlineRegex = regexp.MustCompile("\r?\n")
|
||||||
|
|
||||||
|
func AboutIndex(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
pythonVersion := utils.RunCommand("python3", "--version")
|
||||||
|
if pythonVersion == "" {
|
||||||
|
pythonVersion = utils.RunCommand("python", "--version")
|
||||||
|
}
|
||||||
|
|
||||||
|
gi, _ := goInfo.GetInfo()
|
||||||
|
|
||||||
|
data := map[string]interface{}{
|
||||||
|
"ytDlpVersion": CachedYtDlpVersion,
|
||||||
|
"goVersion": strings.TrimPrefix(utils.RunCommand("go", "version"), "go version "),
|
||||||
|
"pythonVersion": strings.TrimPrefix(pythonVersion, "Python "),
|
||||||
|
"ffmpegVersion": newlineRegex.Split(utils.RunCommand("ffmpeg", "-version"), -1),
|
||||||
|
"os": gi.OS,
|
||||||
|
"kernel": gi.Kernel,
|
||||||
|
"core": gi.Core,
|
||||||
|
"platform": gi.Platform,
|
||||||
|
"hostname": gi.Hostname,
|
||||||
|
"cpus": gi.CPUs,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := aboutIndexTmpl.Execute(w, data); err != nil {
|
||||||
|
log.Error().Msgf("Error rendering template: %v", err)
|
||||||
|
http.Error(w, "Internal error", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"io"
|
"io"
|
||||||
|
"media-roller/src/utils"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -61,17 +61,7 @@ func UpdateYtDlp() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetInstalledVersion() string {
|
func GetInstalledVersion() string {
|
||||||
cmd := exec.Command("yt-dlp", "--version")
|
version := utils.RunCommand("yt-dlp", "--version")
|
||||||
|
|
||||||
var s bytes.Buffer
|
|
||||||
cmd.Stdout = &s
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
log.Error().Err(err).Msgf("Error getting installed version")
|
|
||||||
}
|
|
||||||
|
|
||||||
version := strings.TrimSpace(s.String())
|
|
||||||
if version == "" {
|
if version == "" {
|
||||||
version = "unknown"
|
version = "unknown"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
src/utils/commands.go
Normal file
23
src/utils/commands.go
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RunCommand(name string, args ...string) string {
|
||||||
|
cmd := exec.Command(name, args...)
|
||||||
|
|
||||||
|
var s bytes.Buffer
|
||||||
|
cmd.Stdout = &s
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
log.Error().Err(err).Msgf("Error running command " + strings.Join(args, " "))
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.TrimSpace(s.String())
|
||||||
|
}
|
||||||
55
templates/media/about.html
Normal file
55
templates/media/about.html
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>about - media-roller</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/static/css//bootstrap.min.css">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container d-flex flex-column text-light">
|
||||||
|
<div class="flex-grow-1"></div>
|
||||||
|
<div class="jumbotron bg-transparent flex-grow-1">
|
||||||
|
<h1 class="display-4"><a class="text-light" href="/">media roller</a></h1>
|
||||||
|
<div>
|
||||||
|
{{ .details }}
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td style="width:110px;">Source</td>
|
||||||
|
<td><a href="https://github.com/rroller/media-roller">https://github.com/rroller/media-roller</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a></td>
|
||||||
|
<td>{{ $.ytDlpVersion }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><a href="https://go.dev/doc/install">Golang</a></td>
|
||||||
|
<td>{{ $.goVersion }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><a href="https://www.python.org/downloads/">Python</a></td>
|
||||||
|
<td>{{ $.pythonVersion }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td>os</td><td>{{ $.os }}</td></tr>
|
||||||
|
<tr><td>kernel</td><td>{{ $.kernel }}</td></tr>
|
||||||
|
<tr><td>core</td><td>{{ $.core }}</td></tr>
|
||||||
|
<tr><td>platform</td><td>{{ $.platform }}</td></tr>
|
||||||
|
<tr><td>hostname</td><td>{{ $.hostname }}</td></tr>
|
||||||
|
<tr><td>cpus</td><td>{{ $.cpus }}</td></tr>
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top"><a href="https://www.ffmpeg.org/download.html">ffmpeg</a></td>
|
||||||
|
<td>{{range $element := .ffmpegVersion}}{{ $element }}<br>{{end}}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<footer>
|
||||||
|
<div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -45,9 +45,8 @@
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
<div>
|
<div>
|
||||||
Running <a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a> version {{ $.ytDlpVersion }}<br>
|
<a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a> version {{ $.ytDlpVersion }}<br>
|
||||||
<p class="text-muted">Source at <a class="text-light" href="https://github.com/rroller/media-roller">https://github.com/rroller/media-roller</a>
|
<p><a href="/about">about media-roller</a></p>
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue