diff --git a/internal/handler/download.go b/internal/handler/download.go index 9573f9c..56220fb 100644 --- a/internal/handler/download.go +++ b/internal/handler/download.go @@ -57,16 +57,35 @@ func (h *Handler) Download(w http.ResponseWriter, r *http.Request) { } } + // Determine thumbnail type + thumbType := "" // "image", "video", "audio", "pdf", or "" + thumbnailURL := "" + 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/") { + thumbType = "audio" + } else if rec.ContentType == "application/pdf" { + thumbType = "pdf" + } + data := map[string]any{ - "ID": rec.ID, - "Filename": rec.Filename, - "Size": rec.SizeBytes, - "ContentType": rec.ContentType, - "UploadedAt": rec.UploadedAt.Format("Jan 2, 2006 at 3:04 PM"), - "Downloads": rec.DownloadCount, - "Previewable": isPreviewable(rec.ContentType), - "ViewURL": "/f/" + id + "/view", - "DownloadURL": "/f/" + id + "/dl", + "ID": rec.ID, + "Filename": rec.Filename, + "Size": rec.SizeBytes, + "ContentType": rec.ContentType, + "UploadedAt": rec.UploadedAt.Format("Jan 2, 2006 at 3:04 PM"), + "Downloads": rec.DownloadCount, + "Previewable": isPreviewable(rec.ContentType), + "ViewURL": "/f/" + id + "/view", + "DownloadURL": "/f/" + id + "/dl", + "ThumbType": thumbType, + "ThumbnailURL": thumbnailURL, } 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 8d0a5c8..72c463d 100644 --- a/web/download.html +++ b/web/download.html @@ -8,23 +8,45 @@