Enhance file download handling and web interface. Update the download handler to support inline previews based on query parameters. Introduce a preview button for supported file types in the web interface, along with corresponding styles for action buttons. This improves user experience by allowing direct file previews without downloads.
This commit is contained in:
@@ -172,7 +172,11 @@ func (a *Agent) handleDownload(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = f.Seek(0, io.SeekStart)
|
||||
}
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="`+strings.ReplaceAll(name, `"`, "'")+`"`)
|
||||
disp := "attachment"
|
||||
if r.URL.Query().Get("inline") == "1" {
|
||||
disp = "inline"
|
||||
}
|
||||
w.Header().Set("Content-Disposition", disp+`; filename="`+strings.ReplaceAll(name, `"`, "'")+`"`)
|
||||
w.Header().Set("Accept-Ranges", "bytes")
|
||||
http.ServeContent(w, r, name, info.ModTime(), f)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user