fix: preserve CHFS shared redirect compatibility
This commit is contained in:
@@ -76,7 +76,17 @@ func (s *Server) Handler() http.Handler {
|
||||
mux.HandleFunc("/chfs/shared/", s.shared)
|
||||
mux.HandleFunc("/chfs/preview", s.preview)
|
||||
mux.HandleFunc("/", s.fileHandler)
|
||||
return s.ipFilter(mux)
|
||||
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Go's ServeMux canonicalizes a subtree route before dispatching.
|
||||
// CHFS v4 deliberately returns a relative 301 from /chfs/shared, so
|
||||
// intercept the exact path before ServeMux gets a chance to rewrite it.
|
||||
if r.URL.Path == "/chfs/shared" {
|
||||
s.shared(w, r)
|
||||
return
|
||||
}
|
||||
mux.ServeHTTP(w, r)
|
||||
})
|
||||
return s.ipFilter(h)
|
||||
}
|
||||
func account(r *http.Request, s *Server) *auth.Account {
|
||||
c, err := r.Cookie("JWT")
|
||||
@@ -659,7 +669,9 @@ func (s *Server) shared(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.RawQuery != "" {
|
||||
location += "?" + r.URL.RawQuery
|
||||
}
|
||||
http.Redirect(w, r, location, http.StatusMovedPermanently)
|
||||
w.Header().Set("Content-Disposition", `attachment;filename="shared"`)
|
||||
w.Header().Set("Location", location)
|
||||
w.WriteHeader(http.StatusMovedPermanently)
|
||||
return
|
||||
}
|
||||
p := strings.Trim(strings.TrimPrefix(r.URL.Path, "/chfs/shared/"), "/")
|
||||
@@ -808,6 +820,7 @@ func (s *Server) downloadDir(w http.ResponseWriter, r *http.Request) {
|
||||
name = "download"
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/zip")
|
||||
// CHFS v4 does not emit Content-Disposition for directory archives.
|
||||
zw := zip.NewWriter(w)
|
||||
defer zw.Close()
|
||||
var walk func(string, string) error
|
||||
|
||||
Reference in New Issue
Block a user