mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 10:04:55 +08:00
feat(release):完成双 release 运维闭环
This commit is contained in:
+36
-9
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user