Repository navigation
fix(storage): show a Cloudflare thumbnail for video files in the admin - #928
Conversation
… 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
|
🚅 Deployed to the SahajCloud-pr-928 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 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;withObjectKeyColumnis the precedent (src/plugins/storage/adminThumbnail.ts:19)consider—ADMIN_THUMBNAIL_SIZEis 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
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
|
Addressed both review findings. Pushed Rebutted — the plugin can own this. The Adopted — 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, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
adminThumbnail.video/*without it, so the next one cannot be missed.Change outline
Behaviour — what fills
thumbnailURLPayload's own upload components draw
thumbnailURL || url, andthumbnailURLcomes fromupload.adminThumbnailalone. With none declared,generateFilePathOrURLis reached with nofilenameand nourlOrPath, so it returnsnull— and a video'surlis the HLS manifest, which no image tag can render.Only the value changes, and only for a video. Every non-video document on
filesandframesresolves tonullexactly 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, filesvideosloses its inline copy.urlFields.tsis untouched by this PR.Preview
previewUrlcolumn, unchanged by this PRvideo/mp4row, then its editormediacard pointing at a video fileTest results
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(177 files, 2329 tests)videos.int(6),storage-utils.int(57),video-admin-thumbnail(9)thumbnailURLis already a Payload base field on every upload collection, andpnpm generate:typesreports no drift. No migration.Both new assertions were watched failing before being kept: deleting
adminThumbnailfrom Frames reddens the guard namingframes; a collection with nomimeTypesand no thumbnail reddens it namingfiles; a hand-rolled closure in place of the helper reddens it namingframes; 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.
frames/81once content exists) and confirm the Stream still renders where the file icon was.mediapoints at a video File — the upload card should show the still too.GET /api/frames/<id>?depth=0should return athumbnailURLending/thumbnails/thumbnail.jpg?height=320.Local dev with no
CLOUDFLARE_STREAM_DELIVERY_URLstill shows the icon, as Videos already did.Notes for reviewer
mimeTypesas video-capable:mimeTypesis optional in Payload and an absent one accepts every type. Keyed on avideo/entry alone, such a collection would drop out of the set silently — this defect, re-armed behind a green guard. All eight upload collections declaremimeTypestoday, so that arm is latent.@/collectionsimport 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.adminThumbnailcase invideos.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 shareduploadOftest helper —tests/utils/testHelpers.tsimportspostgresAdapter/getPayload, which must not enter the unit lane. Extracting the env-stub trio — thevi.mockfactory cannot be shared, and the rest is byte-identical to two sibling specs.urlrather than a 320 variant. Separately,previewUrlFieldstill hand-rollsstartsWith('video/')instead of callinggetMimeCategory— behaviourally identical, pre-existing, and the one remaining copy of that test insrc/plugins/storage/.Detail
Rejected: a
storagePlugintransform applied to every upload collection, the waywithUploadNoticeis (#892). It works —buildConfigruns plugins beforesanitizeConfig, andwithObjectKeyColumnalready 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.tsregisters nostoragePlugin, so a plugin-stage mount never reaches anypayload.collections[…].configa spec can read: measured, it reddensvideos.int.spec.ts'sadminThumbnailcase, and leaves fixtures as the only thing any spec could assert against. Registering the plugin under test would put_objectKeyand the R2 filename hooks into all 84 int schemas, which is not a bug fix's change to make.docs/rules/storage.mdrecords the measurement so the next reader stops where this one did.Fixture pre-mortem. The guard uses no fixture: it walks the real
collectionsarray, because which collections admit video is the thing under test. Verified againstsrc/collections/{Videos,Frames,Files}/*.ts— exactly those three list avideo/*entry, and no other file undersrc/collections/contains a'video/string.Security review ran (
src/plugins/storage/matches this repo's trigger paths) and found nothing.filenameis interpolated unencoded, butCLOUDFLARE_STREAM_DELIVERY_URLalready carries scheme and authority so a value lands strictly in the path, and for avideo/*document the filename is Cloudflare's own Stream uid, not caller-chosen.adminThumbnailis in Payload'sserverOnlyUploadProperties, so the function never reaches the client config. The value is the same URLpreviewUrlalready exposes on all three collections.Reviewed with
/simplify(four lenses) and/code-review high;comment-lint.mjs --base origin/mainreports 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