package httpapi import ( "net/http" "time" ) // handleUpdateCheck reports whether a newer panel build is available. func (s *Server) handleUpdateCheck(w http.ResponseWriter, r *http.Request) { if !s.updater.Enabled() { writeOK(w, s.updater.DisabledInfo()) return } info, err := s.updater.Check(r.Context()) if err != nil { writeJSON(w, http.StatusBadGateway, Envelope{Code: 502, Msg: "检查更新失败: " + err.Error()}) return } writeOK(w, info) } // handleUpdateApply downloads, verifies and installs the newest build, then // asks systemd to restart the panel. func (s *Server) handleUpdateApply(w http.ResponseWriter, r *http.Request) { var req struct { Confirm string `json:"confirm"` } if err := decodeJSON(w, r, &req, 4<<10); err != nil { writeErr(w, err) return } // An explicit phrase keeps a stray JSON client from replacing the binary. if req.Confirm != "UPDATE" { writeJSON(w, http.StatusBadRequest, Envelope{Code: 400, Msg: "确认信息不正确"}) return } started := time.Now() res, err := s.updater.Apply(r.Context()) if err != nil { s.audit(r, "system", "update", "panel", "failed", started) writeJSON(w, http.StatusBadRequest, Envelope{Code: 400, Msg: err.Error()}) return } s.audit(r, "system", "update", res.Version, "ok", started) writeOK(w, res) }