forked from jriou/coller
feat: Add Command-line clients link and web page
Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
ff92e30232
commit
70d3892b15
7 changed files with 166 additions and 30 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue