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,62 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sea-vhost/internal/scope"
|
||||
"sea-vhost/internal/store"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (s *Server) siteRuntime(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := projectID(r)
|
||||
sid, e := siteID(r)
|
||||
if err != nil || e != nil {
|
||||
writeError(w, 400, "网站编号无效")
|
||||
return
|
||||
}
|
||||
u := currentUser(r)
|
||||
if r.Method == "GET" {
|
||||
p, e := s.store.ProjectForUser(r.Context(), u, id)
|
||||
if e != nil {
|
||||
writeError(w, 404, "主机不存在")
|
||||
return
|
||||
}
|
||||
if _, e = s.store.Site(r.Context(), p.TenantID, id, sid); e != nil {
|
||||
writeError(w, 404, "网站不存在")
|
||||
return
|
||||
}
|
||||
jobs, e := s.store.RuntimeJobs(scope.WithNode(r.Context(), p.NodeID))
|
||||
if e != nil {
|
||||
writeError(w, 500, "无法读取环境任务")
|
||||
return
|
||||
}
|
||||
own := []store.RuntimeJob{}
|
||||
for _, j := range jobs {
|
||||
if j.SiteID != nil && *j.SiteID == sid {
|
||||
own = append(own, j)
|
||||
}
|
||||
}
|
||||
writeJSON(w, 200, map[string]any{"jobs": own})
|
||||
return
|
||||
}
|
||||
var input struct {
|
||||
Runtime string `json:"runtime"`
|
||||
Version string `json:"version"`
|
||||
EntryFile string `json:"entryFile"`
|
||||
}
|
||||
if decodeJSON(r, &input) != nil {
|
||||
writeError(w, 400, "环境设置格式无效")
|
||||
return
|
||||
}
|
||||
job, err := s.projects.SubmitSiteRuntime(r.Context(), u, id, sid, input.Runtime, input.Version, input.EntryFile)
|
||||
detail := "提交网站运行环境切换任务"
|
||||
if err != nil {
|
||||
detail = err.Error()
|
||||
}
|
||||
s.store.Log(r.Context(), u.TenantID, u.ID, "update", "site_runtime", strconv.FormatUint(sid, 10), requestClientIP(r), err == nil, detail)
|
||||
if err != nil {
|
||||
writeError(w, 422, err.Error())
|
||||
return
|
||||
}
|
||||
writeJSON(w, 202, map[string]any{"jobId": job})
|
||||
}
|
||||
Reference in new issue
Block a user