Refactor file download handling to simplify browser download process and ensure proper content disposition for file downloads
This commit is contained in:
BIN
go_cloud/api
BIN
go_cloud/api
Binary file not shown.
@@ -2979,8 +2979,13 @@ func publicFileDownloadHandler(w http.ResponseWriter, r *http.Request, db *datab
|
||||
return
|
||||
}
|
||||
|
||||
// Get WebDAV client for org
|
||||
client, err := getUserWebDAVClient(r.Context(), db, uuid.Nil, "https://of.b0esche.cloud", cfg.NextcloudUser, cfg.NextcloudPass)
|
||||
if file.UserID == nil {
|
||||
errors.WriteError(w, errors.CodeNotFound, "File not accessible", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
// Get WebDAV client for the file's owner
|
||||
client, err := getUserWebDAVClient(r.Context(), db, *file.UserID, cfg.NextcloudURL, cfg.NextcloudUser, cfg.NextcloudPass)
|
||||
if err != nil {
|
||||
errors.LogError(r, err, "Failed to get WebDAV client")
|
||||
errors.WriteError(w, errors.CodeInternal, "Server error", http.StatusInternalServerError)
|
||||
@@ -3001,6 +3006,9 @@ func publicFileDownloadHandler(w http.ResponseWriter, r *http.Request, db *datab
|
||||
w.Header()[k] = v
|
||||
}
|
||||
|
||||
// Ensure download behavior
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", file.Name))
|
||||
|
||||
// Copy body
|
||||
io.Copy(w, resp.Body)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user