Fix PDF iframe sizing and properly encode Content-Disposition filename headers
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m1s
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m1s
This commit is contained in:
parent
e392da3699
commit
467fe30704
2 changed files with 7 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
}`}
|
||||
|
|
|
|||
Reference in a new issue