Refactor file download handling to simplify browser download process and ensure proper content disposition for file downloads

This commit is contained in:
Leon Bösche
2026-01-24 21:11:25 +01:00
parent 6bbdc157cb
commit 828b63c8c8
3 changed files with 15 additions and 26 deletions

Binary file not shown.

View File

@@ -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)
}