feat: Add Command-line clients link and web page

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2025-09-20 06:36:28 +02:00
commit 70d3892b15
Signed by: jriou
GPG key ID: 9A099EDA51316854
7 changed files with 166 additions and 30 deletions

View file

@ -19,7 +19,12 @@ import (
"git.riou.xyz/jriou/coller/internal"
)
var passwordLength = internal.MIN_PASSWORD_LENGTH
var (
passwordLength = internal.MIN_PASSWORD_LENGTH
supportedOSes = []string{"linux", "darwin"}
supportedArches = []string{"amd64", "arm64"}
supportedClients = []string{"coller", "copier"}
)
type Server struct {
logger *slog.Logger
@ -405,6 +410,42 @@ func (h *GetProtectedWebNoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Re
h.Templates.ExecuteTemplate(w, "note", h.PageData)
}
type ClientsHandler struct {
Templates *template.Template
PageData PageData
logger *slog.Logger
}
func (h *ClientsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.logger.Debug("rendering clients web page")
h.Templates.ExecuteTemplate(w, "clients", h.PageData)
}
type ClientHandler struct {
logger *slog.Logger
version string
}
func (h *ClientHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.logger.Debug("rendering client redirection")
vars := mux.Vars(r)
os := vars["os"]
arch := vars["arch"]
clientName := vars["clientName"]
if !internal.InSlice(supportedOSes, os) || !internal.InSlice(supportedArches, arch) || !internal.InSlice(supportedClients, clientName) {
w.WriteHeader(http.StatusNotFound)
return
}
version := h.version
if version == "" {
version = "latest"
}
http.Redirect(w, r, fmt.Sprintf("https://git.riou.xyz/jriou/%s/releases/download/%s/%s-%s-%s", clientName, version, clientName, os, arch), http.StatusMovedPermanently)
}
//go:embed templates/*
var templatesFS embed.FS
@ -456,6 +497,14 @@ func (s *Server) Start() error {
}
r.Path("/create").Handler(createNoteWithFormHandler).Methods("POST")
clientsHandler := &ClientsHandler{
Templates: templates,
PageData: p,
logger: s.logger,
}
r.Path("/clients.html").Handler(clientsHandler).Methods("GET")
r.Path("/clients/{os:[a-z]+}-{arch:[a-z0-9]+}/{clientName:[a-z]+}").Handler(&ClientHandler{logger: s.logger, version: p.Version}).Methods("GET")
protectedWebNoteHandler := &GetProtectedWebNoteHandler{
Templates: templates,
PageData: p,

View file

@ -0,0 +1,62 @@
{{define "clients"}}
<!DOCTYPE html>
<html lang="en" data-bs-theme="light">
{{block "head" .}}{{end}}
<body>
{{block "header" .}}{{end}}
<div class="container mb-4">
<p class="fs-4">Command-line clients</p>
</div>
<div class="container mb-4">
<table class="table">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Docs</th>
<th scope="col">OS</th>
<th scope="col">Arch</th>
<th scope="col">Download</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row" rowspan="2">coller</th>
<td rowspan="2"><a
href="https://git.riou.xyz/jriou/coller/src/{{if .Version}}tag/{{.Version}}{{else}}branch/main{{end}}/src/cmd/coller/README.md">📄</a>
</td>
<td>Linux</td>
<td>x86-64</td>
<td><a href="/clients/linux-amd64/coller">💾</a></td>
</tr>
<tr>
<td>macOS</td>
<td>ARM64</td>
<td><a href="/clients/darwin-arm64/coller">💾</a></td>
</tr>
<tr>
<th scope="row" rowspan="2">copier</th>
<td rowspan="2"><a
href="https://git.riou.xyz/jriou/coller/src/{{if .Version}}tag/{{.Version}}{{else}}branch/main{{end}}/src/cmd/copier/README.md">📄</a>
</td>
<td>Linux</td>
<td>x86-64</td>
<td><a href="/clients/linux-amd64/copier">💾</a></td>
</tr>
<tr>
<td>macOS</td>
<td>ARM64</td>
<td><a href="/clients/darwin-arm64/copier">💾</a></td>
</tr>
</tbody>
</table>
</div>
{{block "footer" .}}{{end}}
</body>
</html>
{{end}}

View file

@ -5,6 +5,11 @@
<a class="d-flex mb-3 mb-md-0 me-md-auto text-dark text-decoration-none" id="titleHeader" href="/">
<span class="fs-3">{{.Title}}</span>
</a>
<ul class="nav nav-pills align-items-center">
<li class="nav-item px-2">
<a href="/clients.html">Command-line clients</a>
</li>
</ul>
<ul class="nav nav-pills align-items-center">
<li class="nav-item">
<div class="form-check form-switch"