feat(release):完成双 release 运维闭环
bat-rust / Build and test Rust (push) Canceled after 0s
bat-rust / Build and test Go API (push) Canceled after 0s

This commit is contained in:
2026-09-12 11:08:04 +08:00
parent 8a77502272
commit 8d57a63697
27 changed files with 3635 additions and 222 deletions
+36 -9
View File
@@ -14,11 +14,6 @@ func (s *Server) serveCDN(w http.ResponseWriter, r *http.Request) {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
idx := s.index()
if idx == nil || idx.ResourceRoot == "" {
http.Error(w, "resource root not ready", http.StatusServiceUnavailable)
return
}
_, rel, err := SplitCDNPath(r.URL.Path)
if err != nil {
http.NotFound(w, r)
@@ -27,15 +22,47 @@ func (s *Server) serveCDN(w http.ResponseWriter, r *http.Request) {
var entry ResourceEntry
var hasEntry bool
if s.cfg.RequireIndexed {
entry, hasEntry = idx.Lookup(rel)
resourceRoot := ""
explicitRelease := false
channel := r.URL.Query().Get("channel")
releaseID := r.URL.Query().Get("release_id")
if channel != "" || releaseID != "" {
explicitRelease = true
channel, releaseID, selectorErr := releaseSelector(r)
if selectorErr != nil {
http.Error(w, selectorErr.Error(), http.StatusBadRequest)
return
}
selected, selectErr := s.loadReleaseDistribution(r, channel, releaseID)
if selectErr != nil {
http.Error(w, selectErr.Error(), http.StatusServiceUnavailable)
return
}
if selected == nil || !selected.Available || selected.ResourceRoot == "" {
http.Error(w, "selected release is not distributable", http.StatusConflict)
return
}
resourceRoot = selected.ResourceRoot
entry, hasEntry = releaseDistributionEntry(selected, rel)
} else {
idx := s.index()
if idx == nil || idx.ResourceRoot == "" {
http.Error(w, "resource root not ready", http.StatusServiceUnavailable)
return
}
resourceRoot = idx.ResourceRoot
if s.cfg.RequireIndexed {
entry, hasEntry = idx.Lookup(rel)
}
}
if explicitRelease || s.cfg.RequireIndexed {
if !hasEntry || !entry.Present || !entry.SizeMatch {
http.NotFound(w, r)
return
}
}
abs, err := ResolveUnderRoot(idx.ResourceRoot, rel, true)
abs, err := ResolveUnderRoot(resourceRoot, rel, true)
if err != nil {
http.NotFound(w, r)
return
@@ -45,7 +72,7 @@ func (s *Server) serveCDN(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r)
return
}
if s.cfg.RequireIndexed && s.cfg.VerifySize {
if (explicitRelease || s.cfg.RequireIndexed) && s.cfg.VerifySize {
if hasEntry && entry.Bytes > 0 && uint64(info.Size()) != entry.Bytes {
http.Error(w, "size mismatch with release index", http.StatusConflict)
return