Skip to content

fix(storage): show a Cloudflare thumbnail for video files in the admin - #928

Merged
sydevs-bot merged 5 commits into
mainfrom
claude/fix-927-video-admin-thumbnail
Oct 13, 2026
Merged

sydevs-bot merged 5 commits into
mainfrom
claude/fix-927-video-admin-thumbnail

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • A video Frame or File showed Payload's generic file icon on its edit page and in upload-field cards. All three video-capable collections now mount one shared adminThumbnail.
  • A unit guard fails naming any collection that admits video/* without it, so the next one cannot be missed.

Change outline

Behaviour — what fills thumbnailURL

Payload's own upload components draw thumbnailURL || url, and thumbnailURL comes from upload.adminThumbnail alone. With none declared, generateFilePathOrURL is reached with no filename and no urlOrPath, so it returns null — and a video's url is the HLS manifest, which no image tag can render.

 thumbnailURL afterRead                     payload/dist/uploads/getBaseFields.js
   upload.adminThumbnail is a function?
-    videos → an inline closure, keyed on filename alone
-    frames → no → generateFilePathOrURL() → null → falls back to `url` → file icon
-    files  → no → generateFilePathOrURL() → null → falls back to `url` → file icon
+    all three → videoAdminThumbnail(doc)   src/plugins/storage/adminThumbnail.ts
+      filename or mimeType not a string     → null
+      getMimeCategory(mimeType) !== 'video' → null    # an image still falls back to `url`
+      no CLOUDFLARE_STREAM_DELIVERY_URL     → null    # never the file route: it 500s in prod
+      else → <delivery>/<uid>/thumbnails/thumbnail.jpg?height=320

Only the value changes, and only for a video. Every non-video document on files and frames resolves to null exactly as it did before.

Files — one declaration instead of three

 src/plugins/storage/
 ├── mimeUtils.ts        # getMimeCategory, now the only video test on this path
+└── adminThumbnail.ts   # videoAdminThumbnail — mounted by videos, frames, files

videos loses its inline copy. urlFields.ts is untouched by this PR.

Preview

Test results

  • Lean gate: ✓ pnpm lint, pnpm typecheck, pnpm typecheck:tests, pnpm test:unit (177 files, 2329 tests)
  • Targeted specs: ✓ videos.int (6), storage-utils.int (57), video-admin-thumbnail (9)
  • Contract step: no schema change — thumbnailURL is already a Payload base field on every upload collection, and pnpm generate:types reports no drift. No migration.
  • Build: N/A — Railway builds the preview

Both new assertions were watched failing before being kept: deleting adminThumbnail from Frames reddens the guard naming frames; a collection with no mimeTypes and no thumbnail reddens it naming files; a hand-rolled closure in place of the helper reddens it naming frames; and dropping the helper's MIME test reddens the four null cases.

Manual verification

Nothing here can prove the picture actually appears — that needs a browser against a deploy with Cloudflare Stream configured.

  1. Open a video Frame's edit page on the preview (frames/81 once content exists) and confirm the Stream still renders where the file icon was.
  2. Open a Path Step whose panel media points at a video File — the upload card should show the still too.
  3. Confirm a Videos document is unchanged, and that an image Frame and a PDF File still look as they did.
  4. GET /api/frames/<id>?depth=0 should return a thumbnailURL ending /thumbnails/thumbnail.jpg?height=320.

Local dev with no CLOUDFLARE_STREAM_DELIVERY_URL still shows the icon, as Videos already did.

Notes for reviewer

  • The guard's key is load-bearing. It is what the per-collection mount is traded against, so it treats an upload collection with no mimeTypes as video-capable: mimeTypes is optional in Payload and an absent one accepts every type. Keyed on a video/ entry alone, such a collection would drop out of the set silently — this defect, re-armed behind a green guard. All eight upload collections declare mimeTypes today, so that arm is latent.
  • The deferred spec-speed follow-up is withdrawn. An earlier revision of this body claimed the @/collections import costs about 6s of the unit lane. It does not: measured twice each way, the lane runs 44.4s with the spec and 45.8s without it. There is nothing to return, so there is no follow-up to file.
  • Dismissed: deleting the now-overlapping adminThumbnail case in videos.int.spec.ts — it asserts the sanitized Payload config, which the unit spec cannot see, and it is the only assertion in the repo that does. A shared uploadOf test helper — tests/utils/testHelpers.ts imports postgresAdapter/getPayload, which must not enter the unit lane. Extracting the env-stub trio — the vi.mock factory cannot be shared, and the rest is byte-identical to two sibling specs.
  • Not widened to images, which the ticket excludes: an image document still hands the edit header the full-size url rather than a 320 variant. Separately, previewUrlField still hand-rolls startsWith('video/') instead of calling getMimeCategory — behaviourally identical, pre-existing, and the one remaining copy of that test in src/plugins/storage/.
Detail

Rejected: a storagePlugin transform applied to every upload collection, the way withUploadNotice is (#892). It works — buildConfig runs plugins before sanitizeConfig, and withObjectKeyColumn already carries the skip-if-declared shape that stops a transform overriding a collection's own value, so "a replacing scalar" is not the obstacle an earlier revision of this body claimed.

It was built, and the cost is the integration lane. tests/utils/testHelpers.ts registers no storagePlugin, so a plugin-stage mount never reaches any payload.collections[…].config a spec can read: measured, it reddens videos.int.spec.ts's adminThumbnail case, and leaves fixtures as the only thing any spec could assert against. Registering the plugin under test would put _objectKey and the R2 filename hooks into all 84 int schemas, which is not a bug fix's change to make. docs/rules/storage.md records the measurement so the next reader stops where this one did.

Fixture pre-mortem. The guard uses no fixture: it walks the real collections array, because which collections admit video is the thing under test. Verified against src/collections/{Videos,Frames,Files}/*.ts — exactly those three list a video/* entry, and no other file under src/collections/ contains a 'video/ string.

Security review ran (src/plugins/storage/ matches this repo's trigger paths) and found nothing. filename is interpolated unencoded, but CLOUDFLARE_STREAM_DELIVERY_URL already carries scheme and authority so a value lands strictly in the path, and for a video/* document the filename is Cloudflare's own Stream uid, not caller-chosen. adminThumbnail is in Payload's serverOnlyUploadProperties, so the function never reaches the client config. The value is the same URL previewUrl already exposes on all three collections.

Reviewed with /simplify (four lenses) and /code-review high; comment-lint.mjs --base origin/main reports no banned phrasing. A review agent left a scratch file in the worktree, which was deleted before the gate re-ran and is not in the diff.

Closes #927

🤖 Written by the sydevs autonomous loop — see what this is

🤖 Generated with Claude Code

https://claude.ai/code/session_01W1tKHsJ3RKWaJ6ShWb8vSv

… panel

Payload's edit header draws `thumbnailURL || url` (`StaticFileDetails`), and
`thumbnailURL` is filled from `upload.adminThumbnail` alone. Only `videos`
declared one, so a video Frame or File fell through to `url` — the HLS
manifest, which an image tag cannot render — and Payload substituted its
generic file icon. The same held for an upload-field card pointing at a video
file, such as a Path Step panel's media.

`videoAdminThumbnail` is that one declaration, now mounted by all three
collections that accept `video/*`. It returns null for anything else, so an
image keeps falling back to `url`, and it never returns the Payload file route:
Cloudflare serves these bytes, not the Worker, so that URL 500s in production.
Videos' inline function is replaced by it, and its explanation moves onto the
helper.

The guard spec walks the real `collections` array and fails naming any
collection that admits `video/*` without an `adminThumbnail` function —
chosen over applying it to every upload collection the way `withUploadNotice`
does (#892), so the behaviour stays readable in each collection's own file.

No schema change: `thumbnailURL` already exists on every upload collection,
and `pnpm generate:types` reports no drift.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01W1tKHsJ3RKWaJ6ShWb8vSv
…size

The guard keyed on `upload.mimeTypes` containing a `video/` entry, but
`mimeTypes` is optional in Payload and an absent one accepts every type,
`video/mp4` included. Such a collection scored `[]`, dropped out of the set,
and was never required to declare a thumbnail — the defect re-armed behind a
green guard. It now treats an upload collection with no `mimeTypes` as
video-capable.

It also asserted only `typeof adminThumbnail === 'function'`, which a
hand-rolled closure satisfies — the drift one shared helper exists to prevent.
It now asserts identity. The collection roster is matched with
`arrayContaining`, so a correctly wired fourth collection does not redden a
spec that would then name the wrong problem.

`ADMIN_THUMBNAIL_SIZE` replaces two independently declared `320`s. The comment
on the old constant claimed `previewUrlField`'s default and the edit header
agreed; nothing enforced it, so a diverging edit would have had Cloudflare
render and cache a second still per video with nothing failing.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01W1tKHsJ3RKWaJ6ShWb8vSv
… couple

The comment claimed the list column and the edit header "resolve to the same
render". It is only `previewUrlField`'s default, and the edit header's image
path never reads it at all — it falls back to `url`, the full-size Images
variant. A collection passing its own `height` diverges from the still, which
is allowed; the comment now says so instead of implying it cannot happen.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01W1tKHsJ3RKWaJ6ShWb8vSv
@railway-app

railway-app Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-928 environment in sahajcloud

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Oct 12, 2026 at 5:04 pm UTC
1 service not affected by this PR
  • mailpit

@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-928 October 12, 2026 16:18 Destroyed
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 12, 2026
@sydevs-bot

sydevs-bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 16:40Z address-review · attempt 1 · session · done
  • 16:40Z address-review · attempt 1 · session
  • 16:30Z review-pr · attempt 1 · session · done
  • 16:30Z review-pr · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

The fix matches the ticket and the behaviour checks out: with no adminThumbnail, Payload 3.90.2 reaches generateFilePathOrURL with neither filename nor urlOrPath and returns null, so every non-video document on files and frames resolves exactly as before. No cross-repo surface moves.

The shape is the question. storagePlugin.ts already carries two config transforms, and one of them does the conditional skip the body says a transform cannot do — so the per-collection mount and its guard spec may be four pieces where one belongs.

Findings

  • should-fix — the plugin can own this; withObjectKeyColumn is the precedent (src/plugins/storage/adminThumbnail.ts:19)
  • consider — ADMIN_THUMBNAIL_SIZE is unticketed and names three different sizes (src/plugins/storage/urlFields.ts:21)

What was checked

Read whole: adminThumbnail.ts, urlFields.ts, mimeUtils.ts, storagePlugin.ts, the three collection configs, the new spec. All eight upload collections declare mimeTypes, so the guard's absent-mimeTypes arm is latent as the body says. videos.int.spec.ts:94 still passes on both cases. Payload's thumbnailURL hook read from node_modules. Consumers: thumbnailURL is read in WeMeditateWeb for songs only (server/content-index.ts:77) — none of the three touched collections.

Measured the deferred follow-up: pnpm test:unit took 44.4s with the new spec, 45.8s with it excluded. The ~6s it cites did not reproduce, so that refactor may not be owed.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread src/plugins/storage/adminThumbnail.ts Resolved
Comment thread src/plugins/storage/urlFields.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 12, 2026
One exported constant named three tunables: `previewUrlField`'s image-variant
width, its height, and the Stream still's height. Only the last is the edit
header's, and a list cell and an edit header are separate things to tune — so
the name promised a coupling the code did not have. 212c62a had already been
spent narrowing the comment rather than the constant.

`adminThumbnail.ts` now declares its own height, and `urlFields.ts` returns to
its two literal defaults, untouched by this PR.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01N1mC4xfpK3a4KbMnUZQ8an
The rule gave "a replacing scalar" as the reason a transform was rejected.
That is wrong: `withObjectKeyColumn` skips a collection declaring the value
itself, in the same file, so a transform need never override one.

The real cost is the integration lane. `tests/utils/testHelpers.ts` registers
no `storagePlugin`, so a plugin-stage mount never reaches the sanitized config
a spec can read — built and measured, it reddens `videos.int.spec.ts`. Record
the measurement, so the next reader has the same idea and stops at the same
place rather than re-deriving it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01N1mC4xfpK3a4KbMnUZQ8an
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-928 October 12, 2026 16:51 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed both review findings. Pushed d9f8a17.

Rebutted — the plugin can own this. The withObjectKeyColumn precedent is real, so the body's "replacing scalar" reason was wrong and is corrected. But the transform reddens videos.int.spec.ts: testHelpers.ts registers no storagePlugin, so a plugin-stage mount reaches no sanitized config a spec can read. Mounts kept, measurement recorded in docs/rules/storage.md.

Adopted — ADMIN_THUMBNAIL_SIZE names three sizes. 55de447 declares the height in adminThumbnail.ts and restores previewUrlField's literals, so urlFields.ts leaves the diff.

Your 44.4s/45.8s measurement also retires the body's ~6s claim, so that follow-up is withdrawn rather than deferred.

Gate: lint, both typechecks, 2329 unit tests, videos.int and storage-utils.int green.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 12, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review October 12, 2026 17:05
@sydevs-bot
sydevs-bot requested a review from Ardnived October 12, 2026 17:05
@sydevs-bot
sydevs-bot enabled auto-merge October 12, 2026 17:05
@sydevs-bot sydevs-bot moved this from Revising to Approved in SYDevelopers Technical Roadmap Oct 13, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 13, 2026
Merged via the queue into main with commit b10c4f9 Oct 13, 2026
50 of 52 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-927-video-admin-thumbnail branch October 13, 2026 13:49
@sydevs-bot sydevs-bot moved this from Approved to Done in SYDevelopers Technical Roadmap Oct 13, 2026

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-928 — d9f8a175 Deployed Oct 12, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(storage): show a Cloudflare thumbnail for video files in the admin

3 participants