change template
This commit is contained in:
@@ -15,6 +15,7 @@ type (
|
|||||||
LinkCmd struct {
|
LinkCmd struct {
|
||||||
os string
|
os string
|
||||||
arch string
|
arch string
|
||||||
|
name string
|
||||||
out string
|
out string
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -33,6 +34,7 @@ Options:
|
|||||||
func (p *LinkCmd) SetFlags(f *flag.FlagSet) {
|
func (p *LinkCmd) SetFlags(f *flag.FlagSet) {
|
||||||
f.StringVar(&p.os, "os", "", "set the operating system")
|
f.StringVar(&p.os, "os", "", "set the operating system")
|
||||||
f.StringVar(&p.arch, "architecture", "", "set the instruction set")
|
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")
|
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{
|
soft.DownloadLinks = append(soft.DownloadLinks, data.DownloadLink{
|
||||||
OS: p.os,
|
OS: p.os,
|
||||||
Arch: p.arch,
|
Arch: p.arch,
|
||||||
|
Name: p.name,
|
||||||
URL: link,
|
URL: link,
|
||||||
})
|
})
|
||||||
d.Softwares[i] = soft
|
d.Softwares[i] = soft
|
||||||
@@ -114,6 +117,10 @@ func (p *LinkCmd) edit(link, slug string) subcommands.ExitStatus {
|
|||||||
l.Arch = p.arch
|
l.Arch = p.arch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(p.name) > 0 {
|
||||||
|
l.Name = p.name
|
||||||
|
}
|
||||||
|
|
||||||
soft.DownloadLinks[y] = l
|
soft.DownloadLinks[y] = l
|
||||||
foundLink = true
|
foundLink = true
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
type (
|
type (
|
||||||
Server struct {
|
Server struct {
|
||||||
r chi.Router
|
r chi.Router
|
||||||
d data.Service
|
d data.Data
|
||||||
port uint16
|
port uint16
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -26,7 +26,7 @@ var index string
|
|||||||
//go:embed templates/description.html
|
//go:embed templates/description.html
|
||||||
var description string
|
var description string
|
||||||
|
|
||||||
func New(port uint16, d data.Service) *Server {
|
func New(port uint16, d data.Data) *Server {
|
||||||
indexTemplate := template.New("index")
|
indexTemplate := template.New("index")
|
||||||
indexTemplate.Parse(index)
|
indexTemplate.Parse(index)
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ func New(port uint16, d data.Service) *Server {
|
|||||||
var soft data.Software
|
var soft data.Software
|
||||||
var found bool
|
var found bool
|
||||||
for _, s := range d.Softwares {
|
for _, s := range d.Softwares {
|
||||||
if s.UUID == softID {
|
if s.Slug == softID {
|
||||||
soft = s
|
soft = s
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,19 +13,46 @@
|
|||||||
<a style="margin-left: 1rem;" class="navbar-brand mb-0 h1" href="/">DownloadHub</a>
|
<a style="margin-left: 1rem;" class="navbar-brand mb-0 h1" href="/">DownloadHub</a>
|
||||||
</nav>
|
</nav>
|
||||||
<div class="container" style="margin-top: 1rem; margin-bottom: 1rem;">
|
<div class="container" style="margin-top: 1rem; margin-bottom: 1rem;">
|
||||||
<h2>{{.Name}} ({{.Version}})</h2>
|
<h2>{{.Name}} v{{.Version}}</h2>
|
||||||
<img width="100%" src="{{index .ScreenshotURLs 0}}" />
|
<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>
|
<p>{{.Description}}</p>
|
||||||
|
{{ if .Description }}
|
||||||
<hr />
|
<hr />
|
||||||
|
{{ end }}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
Download
|
Assets
|
||||||
</div>
|
</div>
|
||||||
<ul class="list-group list-group-flush">
|
<ul class="list-group list-group-flush">
|
||||||
{{range .DownloadLinks}}
|
{{range .DownloadLinks}}
|
||||||
<a href="{{.URL}}">
|
<a href="{{.URL}}">
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
{{.OS}} ({{.Arch}})
|
{{ if .Name }}
|
||||||
|
{{ if .OS }}
|
||||||
|
{{ .Name }} - {{ .OS }}/{{ .Arch }}
|
||||||
|
{{ else }}
|
||||||
|
{{ .Name }}
|
||||||
|
{{ end }}
|
||||||
|
{{ else }}
|
||||||
|
{{ .OS }}/{{ .Arch }}
|
||||||
|
{{ end }}
|
||||||
</li>
|
</li>
|
||||||
</a>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
@@ -12,19 +12,22 @@
|
|||||||
<nav class="navbar navbar-light bg-light">
|
<nav class="navbar navbar-light bg-light">
|
||||||
<span style="margin-left: 1rem;" class="navbar-brand mb-0 h1">DownloadHub</span>
|
<span style="margin-left: 1rem;" class="navbar-brand mb-0 h1">DownloadHub</span>
|
||||||
</nav>
|
</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;">
|
<div class="container" style="margin-top: 1rem;">
|
||||||
{{range .}}
|
{{ range . }}
|
||||||
<div class="row">
|
<div class="card" style="width: 18rem;">
|
||||||
<div class="col-3">
|
{{ if .ScreenshotURLs }}
|
||||||
<img width="100%" src="{{index .ScreenshotURLs 0}}" />
|
<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>
|
||||||
<div class="col">
|
|
||||||
<h2><a href="/d/{{.UUID}}">{{.Name}}</a></h2>
|
|
||||||
<p>{{.Description}}</p>
|
|
||||||
</div>
|
</div>
|
||||||
<hr style="margin-top: 1rem;" />
|
{{ end }}
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js"
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js"
|
||||||
|
|||||||
@@ -16,12 +16,15 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
slog.Info("loading configuration...")
|
slog.Info("loading configuration...")
|
||||||
d := data.Load(configFile)
|
d, err := data.Load(configFile)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
slog.Info("configuration loaded!")
|
slog.Info("configuration loaded!")
|
||||||
|
|
||||||
slog.Info(fmt.Sprintf("starting server on :%d", port))
|
slog.Info(fmt.Sprintf("starting server on :%d", port))
|
||||||
s := api.New(uint16(port), d)
|
s := api.New(uint16(port), d)
|
||||||
err := s.Serve()
|
err = s.Serve()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
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
|
COPY . /src
|
||||||
|
|
||||||
RUN cd /src \
|
RUN cd /src \
|
||||||
&& go build -o downloadhub \
|
&& go build -o downloadhub ./cmd/server \
|
||||||
&& mkdir -p ./fs/var/opt/downloadhub \
|
&& mkdir -p ./fs/var/opt/downloadhub \
|
||||||
&& mkdir -p ./fs/opt/downloadhub \
|
&& mkdir -p ./fs/opt/downloadhub \
|
||||||
&& cp downloadhub ./fs/opt/downloadhub/downloadhub
|
&& cp downloadhub ./fs/opt/downloadhub/downloadhub
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -1,9 +1,9 @@
|
|||||||
module downloadhub
|
module downloadhub
|
||||||
|
|
||||||
go 1.22
|
go 1.25
|
||||||
|
|
||||||
require (
|
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/subcommands v1.2.0
|
||||||
github.com/google/uuid v1.6.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.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618=
|
||||||
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
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 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
|
||||||
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type (
|
|||||||
DownloadLink struct {
|
DownloadLink struct {
|
||||||
OS string `json:"os"`
|
OS string `json:"os"`
|
||||||
Arch string `json:"arch"`
|
Arch string `json:"arch"`
|
||||||
|
Name string `json:"name"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user