From 27fd6fa4f5f6dae278094655ef41420c839d7eb2 Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 22 May 2026 19:06:21 -0700 Subject: [PATCH] Minor appearance changes, sharing live preview --- backend/handlers/sharing.go | 7 +++++++ frontend/src/app/share/[id]/page.tsx | 15 ++++++++++++++- frontend/src/components/FileExplorer.tsx | 5 ++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/backend/handlers/sharing.go b/backend/handlers/sharing.go index 1f1f478..1a72244 100644 --- a/backend/handlers/sharing.go +++ b/backend/handlers/sharing.go @@ -2,6 +2,7 @@ package handlers import ( "fmt" + "mime" "os" "path/filepath" "time" @@ -203,10 +204,16 @@ func (h *ShareHandler) GetPublicShare(c *fiber.Ctx) error { // For simplicity, we'll return a short-lived download token JWT. // Actually, easier: the frontend calls GET /api/public/download/:id?pwd=xxx + mimeType := mime.TypeByExtension(filepath.Ext(info.Name())) + if mimeType == "" { + mimeType = "application/octet-stream" + } + return c.JSON(fiber.Map{ "name": filepath.Base(path), "size": info.Size(), "is_dir": info.IsDir(), + "mime_type": mimeType, }) } diff --git a/frontend/src/app/share/[id]/page.tsx b/frontend/src/app/share/[id]/page.tsx index f672cd0..8de2cdd 100644 --- a/frontend/src/app/share/[id]/page.tsx +++ b/frontend/src/app/share/[id]/page.tsx @@ -11,7 +11,7 @@ export default function PublicSharePage({ params }: { params: Promise<{ id: stri const [error, setError] = useState(null); const [requirePassword, setRequirePassword] = useState(false); const [password, setPassword] = useState(''); - const [fileInfo, setFileInfo] = useState<{ name: string; size: number; is_dir: boolean } | null>(null); + const [fileInfo, setFileInfo] = useState<{ name: string; size: number; is_dir: boolean; mime_type?: string } | null>(null); useEffect(() => { fetchShareInfo(); @@ -112,6 +112,11 @@ export default function PublicSharePage({ params }: { params: Promise<{ id: stri ); } + const isImage = fileInfo?.mime_type?.startsWith('image/'); + const isVideo = fileInfo?.mime_type?.startsWith('video/'); + const isAudio = fileInfo?.mime_type?.startsWith('audio/'); + const isPdf = fileInfo?.mime_type === 'application/pdf'; + const downloadUrl = fileInfo ? api.getPublicDownloadUrl(id, password) : ''; return (
@@ -121,6 +126,14 @@ export default function PublicSharePage({ params }: { params: Promise<{ id: stri
+ ) : isImage ? ( + {fileInfo?.name} + ) : isVideo ? ( +