Return the mime type with the file for easier panel integration
This commit is contained in:
parent
8d8ec70683
commit
c943246e33
13
http.go
13
http.go
|
@ -219,13 +219,16 @@ func (rt *Router) routeServerFileRead(w http.ResponseWriter, r *http.Request, ps
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
st, err := os.Stat(cleaned)
|
st, err := s.Filesystem.Stat(cleaned)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
zap.S().Errorw("failed to stat file for reading", zap.String("path", ps.ByName("path")), zap.String("server", s.Uuid), zap.Error(err))
|
zap.S().Errorw("failed to stat file for reading", zap.String("path", ps.ByName("path")), zap.String("server", s.Uuid), zap.Error(err))
|
||||||
|
|
||||||
|
http.Error(w, "failed to stat file", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
http.Error(w, "failed to stat file", http.StatusInternalServerError)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,12 +243,14 @@ func (rt *Router) routeServerFileRead(w http.ResponseWriter, r *http.Request, ps
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
|
w.Header().Set("X-Mime-Type", st.Mimetype)
|
||||||
|
w.Header().Set("Content-Length", strconv.Itoa(int(st.Info.Size())))
|
||||||
|
|
||||||
// If a download parameter is included in the URL go ahead and attach the necessary headers
|
// If a download parameter is included in the URL go ahead and attach the necessary headers
|
||||||
// so that the file can be downloaded.
|
// so that the file can be downloaded.
|
||||||
if r.URL.Query().Get("download") != "" {
|
if r.URL.Query().Get("download") != "" {
|
||||||
w.Header().Set("Content-Disposition", "attachment; filename="+st.Name())
|
w.Header().Set("Content-Disposition", "attachment; filename="+st.Info.Name())
|
||||||
w.Header().Set("Content-Type", "application/octet-stream")
|
w.Header().Set("Content-Type", "application/octet-stream")
|
||||||
w.Header().Set("Content-Length", strconv.Itoa(int(st.Size())))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bufio.NewReader(f).WriteTo(w)
|
bufio.NewReader(f).WriteTo(w)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user