feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,84 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (s *Server) adminRuntimeMaintenance(w http.ResponseWriter, r *http.Request) {
|
||||
targets, jobs, err := s.projects.RuntimeMaintenanceState(r.Context())
|
||||
if err != nil {
|
||||
writeError(w, 502, "无法读取运行环境维护状态")
|
||||
return
|
||||
}
|
||||
writeJSON(w, 200, map[string]any{"sites": targets, "jobs": jobs})
|
||||
}
|
||||
func (s *Server) adminUpdatePHPPatch(w http.ResponseWriter, r *http.Request) {
|
||||
var input struct {
|
||||
Branch string `json:"branch"`
|
||||
Target string `json:"target"`
|
||||
}
|
||||
if decodeJSON(r, &input) != nil {
|
||||
writeError(w, 400, "请选择 PHP 分支与目标补丁版本")
|
||||
return
|
||||
}
|
||||
id, err := s.projects.SubmitPHPPatch(r.Context(), input.Branch, input.Target)
|
||||
s.logRuntimeMaintenance(r, "php_patch", "PHP/"+input.Target, err)
|
||||
if err != nil {
|
||||
writeError(w, 422, err.Error())
|
||||
return
|
||||
}
|
||||
writeJSON(w, 202, map[string]any{"jobId": id})
|
||||
}
|
||||
func (s *Server) adminMigrateSiteRuntime(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseUint(r.PathValue("siteID"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
writeError(w, 400, "站点编号无效")
|
||||
return
|
||||
}
|
||||
var input struct {
|
||||
Version string `json:"version"`
|
||||
AllowBranchChange bool `json:"allowBranchChange"`
|
||||
EntryFile string `json:"entryFile"`
|
||||
}
|
||||
if decodeJSON(r, &input) != nil || input.Version == "" {
|
||||
writeError(w, 400, "请选择目标版本")
|
||||
return
|
||||
}
|
||||
jobID, err := s.projects.SubmitRuntimeMigration(r.Context(), id, input.Version, input.AllowBranchChange, input.EntryFile)
|
||||
s.logRuntimeMaintenance(r, "migrate", r.PathValue("siteID")+"/"+input.Version, err)
|
||||
if err != nil {
|
||||
writeError(w, 422, err.Error())
|
||||
return
|
||||
}
|
||||
writeJSON(w, 202, map[string]any{"jobId": jobID})
|
||||
}
|
||||
func (s *Server) adminResumeRuntimeMaintenance(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseUint(r.PathValue("jobID"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
writeError(w, 400, "任务编号无效")
|
||||
return
|
||||
}
|
||||
err = s.projects.ResumeRuntimeMaintenance(r.Context(), id)
|
||||
s.logRuntimeMaintenance(r, "resume", r.PathValue("jobID"), err)
|
||||
if err != nil {
|
||||
writeError(w, 409, "任务无法恢复,或已有其他维护任务正在执行")
|
||||
return
|
||||
}
|
||||
writeJSON(w, 202, map[string]bool{"ok": true})
|
||||
}
|
||||
func (s *Server) adminCheckRuntimeUpdates(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := s.projects.SubmitRuntimeCheck(r.Context())
|
||||
if err != nil {
|
||||
writeError(w, 409, err.Error())
|
||||
return
|
||||
}
|
||||
writeJSON(w, 202, map[string]any{"jobId": id})
|
||||
}
|
||||
func (s *Server) logRuntimeMaintenance(r *http.Request, action, target string, err error) {
|
||||
detail := "已提交运行环境维护任务"
|
||||
if err != nil {
|
||||
detail = err.Error()
|
||||
}
|
||||
s.store.Log(r.Context(), nil, currentUser(r).ID, action, "runtime_maintenance", target, requestClientIP(r), err == nil, detail)
|
||||
}
|
||||
Reference in new issue
Block a user