CI / test (push) Successful in 4m48s
Saving settings replaced the whole Settings value, which would have dropped SelfEdgeID and made the next start create a second self edge with a new token. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
32 lines
947 B
Go
32 lines
947 B
Go
package hammerhead
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
|
|
"git.veillax.com/Veillax/reef/selfupdate"
|
|
)
|
|
|
|
// checkUpdate asks the release server whether a newer Hammerhead exists. It only looks: updating is
|
|
// left to auto-update or to the person running the server.
|
|
func (s *Server) checkUpdate(w http.ResponseWriter, r *http.Request, p *principal) {
|
|
o := s.opts
|
|
cfg := selfupdate.Config{Server: o.UpdateServer, Repo: o.UpdateRepo, App: "hammerhead", Current: o.Version}
|
|
if cfg.Server == "" {
|
|
cfg.Server = "https://git.veillax.com"
|
|
}
|
|
if cfg.Repo == "" {
|
|
cfg.Repo = "Veillax/hammerhead"
|
|
}
|
|
ctx, cancel := context.WithTimeout(r.Context(), 20*time.Second)
|
|
defer cancel()
|
|
out := map[string]any{"current": o.Version, "autoUpdate": o.AutoUpdate, "checked": time.Now()}
|
|
latest, newer, err := selfupdate.Check(ctx, cfg)
|
|
out["latest"], out["newer"] = latest, newer
|
|
if err != nil {
|
|
out["error"] = err.Error()
|
|
}
|
|
writeJSON(w, 200, out)
|
|
}
|