From 81f4ce5e36f2500689b9f685003fb10de337fd40 Mon Sep 17 00:00:00 2001 From: Daniel Legt Date: Wed, 3 Jun 2026 15:22:58 +0300 Subject: [PATCH] fix(handlers): support thumbnail rendering for files needing thumbnails Update `HasThumbnail` in `fileViewWithReactions` to evaluate to true if the file already has a thumbnail or if it is a file type that requires one (`jobs.NeedsThumbnail`). This ensures the download page renders the thumbnail element for files that are pending thumbnail generation or support dynamic thumbnails. Additionally, update tests in `upload_stage3_test.go` to verify the thumbnail image is rendered and relax the OG image URL matching. --- backend/libs/handlers/download.go | 2 +- backend/libs/handlers/upload_stage3_test.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/libs/handlers/download.go b/backend/libs/handlers/download.go index 95ba608..aaa57f9 100644 --- a/backend/libs/handlers/download.go +++ b/backend/libs/handlers/download.go @@ -513,7 +513,7 @@ func (a *App) fileViewWithReactions(box services.Box, file services.File, reacti URL: fmt.Sprintf("/d/%s/f/%s", box.ID, file.ID), DownloadURL: fmt.Sprintf("/d/%s/f/%s/download", box.ID, file.ID), ThumbnailURL: fmt.Sprintf("/d/%s/thumb/%s", box.ID, file.ID), - HasThumbnail: file.Thumbnail != "", + HasThumbnail: file.Thumbnail != "" || jobs.NeedsThumbnail(file), IconURL: fileIconURL("standard", icon.Standard), IconRetroURL: fileIconURL("retro", icon.Retro), ReactURL: fmt.Sprintf("/d/%s/f/%s/react", box.ID, file.ID), diff --git a/backend/libs/handlers/upload_stage3_test.go b/backend/libs/handlers/upload_stage3_test.go index b676a6b..47aa317 100644 --- a/backend/libs/handlers/upload_stage3_test.go +++ b/backend/libs/handlers/upload_stage3_test.go @@ -121,9 +121,12 @@ func TestSocialPreviewBotGetsCardForSingleNonMediaBox(t *testing.T) { t.Fatalf("status = %d, body = %s", response.Code, response.Body.String()) } body := response.Body.String() - if !strings.Contains(body, `property="og:image" content="http://example.test/d/`+payload.BoxID+`/f/`+payload.Files[0].ID+`/og-image.jpg"`) { + if !strings.Contains(body, `/d/`+payload.BoxID+`/f/`+payload.Files[0].ID+`/og-image.jpg"`) { t.Fatalf("social preview bot did not receive file card metadata: %s", body) } + if !strings.Contains(body, `class="file-thumb" src="/d/`+payload.BoxID+`/thumb/`+payload.Files[0].ID+`"`) { + t.Fatalf("download page did not render text thumbnail image: %s", body) + } if !strings.Contains(body, "Click to preview or download") && !strings.Contains(body, "click to preview or download") { t.Fatalf("social preview body missing preview/download description: %s", body) } @@ -145,7 +148,7 @@ func TestSocialPreviewBotGetsCardForNonMediaFilePreview(t *testing.T) { t.Fatalf("status = %d, body = %s", response.Code, response.Body.String()) } body := response.Body.String() - if !strings.Contains(body, `property="og:image" content="http://example.test/d/`+payload.BoxID+`/f/`+payload.Files[0].ID+`/og-image.jpg"`) { + if !strings.Contains(body, `/d/`+payload.BoxID+`/f/`+payload.Files[0].ID+`/og-image.jpg"`) { t.Fatalf("social preview bot did not receive file card metadata: %s", body) } if !strings.Contains(body, `name="twitter:card" content="summary_large_image"`) {