change template
This commit is contained in:
@@ -15,6 +15,7 @@ type (
|
||||
LinkCmd struct {
|
||||
os string
|
||||
arch string
|
||||
name string
|
||||
out string
|
||||
}
|
||||
)
|
||||
@@ -33,6 +34,7 @@ Options:
|
||||
func (p *LinkCmd) SetFlags(f *flag.FlagSet) {
|
||||
f.StringVar(&p.os, "os", "", "set the operating system")
|
||||
f.StringVar(&p.arch, "architecture", "", "set the instruction set")
|
||||
f.StringVar(&p.name, "name", "", "set the name or label of the link")
|
||||
f.StringVar(&p.out, "out", "./config.json", "path to the configuration file")
|
||||
}
|
||||
|
||||
@@ -74,6 +76,7 @@ func (p *LinkCmd) add(link, slug string) subcommands.ExitStatus {
|
||||
soft.DownloadLinks = append(soft.DownloadLinks, data.DownloadLink{
|
||||
OS: p.os,
|
||||
Arch: p.arch,
|
||||
Name: p.name,
|
||||
URL: link,
|
||||
})
|
||||
d.Softwares[i] = soft
|
||||
@@ -114,6 +117,10 @@ func (p *LinkCmd) edit(link, slug string) subcommands.ExitStatus {
|
||||
l.Arch = p.arch
|
||||
}
|
||||
|
||||
if len(p.name) > 0 {
|
||||
l.Name = p.name
|
||||
}
|
||||
|
||||
soft.DownloadLinks[y] = l
|
||||
foundLink = true
|
||||
break
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
type (
|
||||
Server struct {
|
||||
r chi.Router
|
||||
d data.Service
|
||||
d data.Data
|
||||
port uint16
|
||||
}
|
||||
)
|
||||
@@ -26,7 +26,7 @@ var index string
|
||||
//go:embed templates/description.html
|
||||
var description string
|
||||
|
||||
func New(port uint16, d data.Service) *Server {
|
||||
func New(port uint16, d data.Data) *Server {
|
||||
indexTemplate := template.New("index")
|
||||
indexTemplate.Parse(index)
|
||||
|
||||
@@ -46,7 +46,7 @@ func New(port uint16, d data.Service) *Server {
|
||||
var soft data.Software
|
||||
var found bool
|
||||
for _, s := range d.Softwares {
|
||||
if s.UUID == softID {
|
||||
if s.Slug == softID {
|
||||
soft = s
|
||||
found = true
|
||||
}
|
||||
|
||||
@@ -13,19 +13,46 @@
|
||||
<a style="margin-left: 1rem;" class="navbar-brand mb-0 h1" href="/">DownloadHub</a>
|
||||
</nav>
|
||||
<div class="container" style="margin-top: 1rem; margin-bottom: 1rem;">
|
||||
<h2>{{.Name}} ({{.Version}})</h2>
|
||||
<img width="100%" src="{{index .ScreenshotURLs 0}}" />
|
||||
<p>{{.Description}}</p>
|
||||
<h2>{{.Name}} v{{.Version}}</h2>
|
||||
<hr/>
|
||||
<div id="carousel" class="carousel slide">
|
||||
<div class="carousel-inner">
|
||||
{{ range .ScreenshotURLs }}
|
||||
<div class="carousel-item">
|
||||
<img src="{{ . }}" class="d-block w-100">
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
<button class="carousel-control-prev" type="button" data-bs-target="#carousel" data-bs-slide="prev">
|
||||
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
|
||||
<span class="visually-hidden">Previous</span>
|
||||
</button>
|
||||
<button class="carousel-control-next" type="button" data-bs-target="#carousel" data-bs-slide="next">
|
||||
<span class="carousel-control-next-icon" aria-hidden="true"></span>
|
||||
<span class="visually-hidden">Next</span>
|
||||
</button>
|
||||
</div>
|
||||
<p>{{.Description}}</p>
|
||||
{{ if .Description }}
|
||||
<hr />
|
||||
{{ end }}
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Download
|
||||
Assets
|
||||
</div>
|
||||
<ul class="list-group list-group-flush">
|
||||
{{range .DownloadLinks}}
|
||||
<a href="{{.URL}}">
|
||||
<li class="list-group-item">
|
||||
{{.OS}} ({{.Arch}})
|
||||
{{ if .Name }}
|
||||
{{ if .OS }}
|
||||
{{ .Name }} - {{ .OS }}/{{ .Arch }}
|
||||
{{ else }}
|
||||
{{ .Name }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ .OS }}/{{ .Arch }}
|
||||
{{ end }}
|
||||
</li>
|
||||
</a>
|
||||
{{end}}
|
||||
|
||||
@@ -12,17 +12,20 @@
|
||||
<nav class="navbar navbar-light bg-light">
|
||||
<span style="margin-left: 1rem;" class="navbar-brand mb-0 h1">DownloadHub</span>
|
||||
</nav>
|
||||
<div style="width: 100%; height: 20rem; background-color: #f2f2f2; display: flex; justify-content: center; align-items: center;">
|
||||
<h1>DownloadHub</h1>
|
||||
</div>
|
||||
<div class="container" style="margin-top: 1rem;">
|
||||
{{ range . }}
|
||||
<div class="row">
|
||||
<div class="col-3">
|
||||
<img width="100%" src="{{index .ScreenshotURLs 0}}" />
|
||||
<div class="card" style="width: 18rem;">
|
||||
{{ if .ScreenshotURLs }}
|
||||
<img src="{{ index .ScreenshotURLs 0 }}" class="card-img-top">
|
||||
{{ end }}
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ .Name }}</h5>
|
||||
<p class="card-text">{{ .Description }}</p>
|
||||
<a href="/d/{{ .Slug }}" class="btn btn-primary">More info</a>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h2><a href="/d/{{.UUID}}">{{.Name}}</a></h2>
|
||||
<p>{{.Description}}</p>
|
||||
</div>
|
||||
<hr style="margin-top: 1rem;" />
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
@@ -16,12 +16,15 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
slog.Info("loading configuration...")
|
||||
d := data.Load(configFile)
|
||||
d, err := data.Load(configFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
slog.Info("configuration loaded!")
|
||||
|
||||
slog.Info(fmt.Sprintf("starting server on :%d", port))
|
||||
s := api.New(uint16(port), d)
|
||||
err := s.Serve()
|
||||
err = s.Serve()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
FROM golang:1.23.1-alpine3.20 as build
|
||||
FROM golang:1.25.0-alpine3.22 as build
|
||||
|
||||
COPY . /src
|
||||
|
||||
RUN cd /src \
|
||||
&& go build -o downloadhub \
|
||||
&& go build -o downloadhub ./cmd/server \
|
||||
&& mkdir -p ./fs/var/opt/downloadhub \
|
||||
&& mkdir -p ./fs/opt/downloadhub \
|
||||
&& cp downloadhub ./fs/opt/downloadhub/downloadhub
|
||||
|
||||
4
go.mod
4
go.mod
@@ -1,9 +1,9 @@
|
||||
module downloadhub
|
||||
|
||||
go 1.22
|
||||
go 1.25
|
||||
|
||||
require (
|
||||
github.com/go-chi/chi/v5 v5.1.0
|
||||
github.com/go-chi/chi/v5 v5.2.2
|
||||
github.com/google/subcommands v1.2.0
|
||||
github.com/google/uuid v1.6.0
|
||||
)
|
||||
|
||||
4
go.sum
4
go.sum
@@ -1,5 +1,5 @@
|
||||
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.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618=
|
||||
github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
|
||||
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
|
||||
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
|
||||
@@ -25,6 +25,7 @@ type (
|
||||
DownloadLink struct {
|
||||
OS string `json:"os"`
|
||||
Arch string `json:"arch"`
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user