forked from jriou/coller
feat: Add clients base URL
- Add `clients_base_url` to define an alternative URL to download clients - Rename `clients_directory` to `clients_base_directory` to download clients locally based on the version. If `show_version` is disabled and `clients_base_directory` are both defined, a redirection to a remote URL with the "latest" version is chosen in order to avoid to disclose the server version. Fixes #43. Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
ab6b03a6d4
commit
b35828d909
4 changed files with 24 additions and 14 deletions
|
@ -232,9 +232,10 @@ func (h *GetProtectedNoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|||
}
|
||||
|
||||
type ClientHandler struct {
|
||||
logger *slog.Logger
|
||||
version string
|
||||
directory string
|
||||
logger *slog.Logger
|
||||
version string
|
||||
baseURL string
|
||||
baseDirectory string
|
||||
}
|
||||
|
||||
func (h *ClientHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -249,14 +250,19 @@ func (h *ClientHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
version := h.version
|
||||
if version == "" {
|
||||
version = "latest"
|
||||
// No disclosure of the version running on the server
|
||||
if h.version == "" {
|
||||
http.Redirect(w, r, fmt.Sprintf("%s/%s/%s-%s-%s", h.baseURL, "latest", clientName, os, arch), http.StatusMovedPermanently)
|
||||
return
|
||||
}
|
||||
|
||||
if h.directory != "" {
|
||||
http.ServeFile(w, r, h.directory+"/"+fmt.Sprintf("%s-%s-%s", clientName, os, arch))
|
||||
if h.baseDirectory != "" {
|
||||
// Serve file locally
|
||||
// Example: ./releases/1.2.0/coller-linux-amd64
|
||||
http.ServeFile(w, r, fmt.Sprintf("%s/%s/%s-%s-%s", h.baseDirectory, h.version, clientName, os, arch))
|
||||
} else {
|
||||
http.Redirect(w, r, fmt.Sprintf("https://git.riou.xyz/jriou/coller/releases/download/%s/%s-%s-%s", version, clientName, os, arch), http.StatusMovedPermanently)
|
||||
// Redirect to a download link
|
||||
// Example: https://git.riou.xyz/jriou/coller/releases/download/1.2.0/coller-linux-amd64
|
||||
http.Redirect(w, r, fmt.Sprintf("%s/%s/%s-%s-%s", h.baseURL, h.version, clientName, os, arch), http.StatusMovedPermanently)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue