diff --git a/internal/handler/download.go b/internal/handler/download.go index 56220fb..9411481 100644 --- a/internal/handler/download.go +++ b/internal/handler/download.go @@ -57,15 +57,11 @@ func (h *Handler) Download(w http.ResponseWriter, r *http.Request) { } } - // Determine thumbnail type + // Determine preview type and generate presigned URL for inline rendering thumbType := "" // "image", "video", "audio", "pdf", or "" - thumbnailURL := "" + previewURL := "" if strings.HasPrefix(rec.ContentType, "image/") { thumbType = "image" - // Generate inline presigned URL for the image thumbnail - if url, err := h.r2.PresignGet(r.Context(), rec.R2Key, rec.Filename, true); err == nil { - thumbnailURL = url - } } else if strings.HasPrefix(rec.ContentType, "video/") { thumbType = "video" } else if strings.HasPrefix(rec.ContentType, "audio/") { @@ -73,6 +69,11 @@ func (h *Handler) Download(w http.ResponseWriter, r *http.Request) { } else if rec.ContentType == "application/pdf" { thumbType = "pdf" } + if thumbType != "" { + if url, err := h.r2.PresignGet(r.Context(), rec.R2Key, rec.Filename, true); err == nil { + previewURL = url + } + } data := map[string]any{ "ID": rec.ID, @@ -84,8 +85,8 @@ func (h *Handler) Download(w http.ResponseWriter, r *http.Request) { "Previewable": isPreviewable(rec.ContentType), "ViewURL": "/f/" + id + "/view", "DownloadURL": "/f/" + id + "/dl", - "ThumbType": thumbType, - "ThumbnailURL": thumbnailURL, + "ThumbType": thumbType, + "PreviewURL": previewURL, } if rec.ExpiresAt != nil { data["ExpiresAt"] = rec.ExpiresAt.Format("Jan 2, 2006 at 3:04 PM") diff --git a/web/download.html b/web/download.html index 72c463d..862fbe6 100644 --- a/web/download.html +++ b/web/download.html @@ -11,30 +11,13 @@