Port agent PRs to GO - 4 (#16652)

### Summary

Port

https://github.com/infiniflow/ragflow/pull/15399
https://github.com/infiniflow/ragflow/pull/16469
This commit is contained in:
qinling0210
2026-07-06 10:58:40 +08:00
committed by GitHub
parent 09eb9dbd21
commit 3d2f60c34f
7 changed files with 301 additions and 99 deletions

View File

@@ -307,14 +307,12 @@ func (h *DocumentHandler) GetDocumentPreview(c *gin.Context) {
}
ext := utility.GetFileExtension(preview.FileName)
if preview.ContentType != "" {
c.Header("Content-Type", preview.ContentType)
}
if utility.ShouldForceAttachment(ext, preview.ContentType) {
c.Header("X-Content-Type-Options", "nosniff")
c.Header("Content-Disposition", "attachment")
}
// Use the shared preview-headers helper so that safe types get
// Content-Disposition: inline with filename, while dangerous
// types (HTML, SVG, XML) fall back to forced attachment with
// nosniff. Mirrors Python document_api.py:2063 which calls
// apply_preview_file_response_headers() with the document name.
utility.SetPreviewFileResponseHeaders(c.Writer.Header(), preview.ContentType, ext, preview.FileName)
c.Data(http.StatusOK, preview.ContentType, preview.Data)
}