From 467fe307048c0be0da30ec0f31ec80c04efb5dd1 Mon Sep 17 00:00:00 2001 From: Elijah Date: Sun, 31 May 2026 22:16:02 -0700 Subject: [PATCH] Fix PDF iframe sizing and properly encode Content-Disposition filename headers --- backend/handlers/files.go | 8 ++++++-- frontend/src/components/FilePreview.tsx | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/handlers/files.go b/backend/handlers/files.go index 1af5bec..43cf7b0 100644 --- a/backend/handlers/files.go +++ b/backend/handlers/files.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "mime" + "net/url" "os" "os/exec" "path/filepath" @@ -1027,10 +1028,13 @@ func (h *FSHandler) Download(c *fiber.Ctx) error { c.Set("Accept-Ranges", "bytes") c.Set("Content-Type", mime.TypeByExtension(filepath.Ext(resolvedPath))) + safeNameQuote := strings.ReplaceAll(info.Name(), "\"", "\\\"") + encodedName := url.PathEscape(info.Name()) + if c.Query("download") == "true" { - c.Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", info.Name())) + c.Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"; filename*=UTF-8''%s", safeNameQuote, encodedName)) } else { - c.Set("Content-Disposition", fmt.Sprintf("inline; filename=\"%s\"", info.Name())) + c.Set("Content-Disposition", fmt.Sprintf("inline; filename=\"%s\"; filename*=UTF-8''%s", safeNameQuote, encodedName)) } // Use Fiber's built-in SendFile which supports Range requests diff --git a/frontend/src/components/FilePreview.tsx b/frontend/src/components/FilePreview.tsx index 3541e1b..8fe0dd7 100644 --- a/frontend/src/components/FilePreview.tsx +++ b/frontend/src/components/FilePreview.tsx @@ -87,7 +87,7 @@ export default function FilePreview({ file, onClose, downloadToken }: FilePrevie exit={{ scale: 0.95, opacity: 0, y: 20 }} onClick={(e) => e.stopPropagation()} className={`relative flex flex-col max-w-[95vw] max-h-[95vh] rounded-2xl overflow-hidden shadow-2xl ${ - (previewType === 'image' || previewType === 'video' || previewType === 'pdf' || previewType === 'stl' || previewType === '3mf' || previewType === 'audio') ? 'w-fit' : 'w-full' + (previewType === 'image' || previewType === 'video' || previewType === 'stl' || previewType === '3mf' || previewType === 'audio') ? 'w-fit' : 'w-full' } ${ (previewType === 'image' || previewType === 'video' || previewType === 'audio') ? 'h-fit' : 'h-full' }`}