fix: resolve thumbnailURL to direct cloud storage URLs - #17347
Open
thedanielmark wants to merge 1 commit into
Open
fix: resolve thumbnailURL to direct cloud storage URLs#17347thedanielmark wants to merge 1 commit into
thedanielmark wants to merge 1 commit into
Conversation
Include sizes.<adminThumbnail>.url in list-view select projections and treat external URLs correctly when serverURL is unset. Fixes payloadcms#12659
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fixes #12659
When using cloud storage with
adminThumbnailset to a string size name (for example'thumbnail'),thumbnailURLcould resolve to/api/{collection}/file/...instead of the direct CDN or S3 URL. This affected admin list thumbnails and any API response that relied onthumbnailURL.Why?
Two independent bugs in core:
appendUploadSelectFieldsFor string
adminThumbnail, the list-view select only projectedsizes.<name>.filename, not.url. Without the stored URL in the projection, thethumbnailURLafterRead hook falls back to building a local API path from the filename.generateFilePathOrURLWhen
serverURLis unset, which is common for relative-URL deployments,urlOrPath.startsWith(serverURL || '')becomesstartsWith(''). That is always true, so external URLs were treated as same-origin and discarded in favor of the local file path.Related: #15988 adds
generateFileURLhooks onthumbnailURLin plugin-cloud-storage. That work is complementary. It regenerates URLs on read whengenerateFileURLis configured. This PR fixes select projection and external URL detection in core.How?
url: trueto thesizes.<adminThumbnail>select inappendUploadSelectFields, matching the behavior of the non-stringadminThumbnailbranch.generateFilePathOrURL, only treaturlOrPathas same-origin whenserverURLis actually configured.Verification
pnpm test:unit appendUploadSelectFields generateFilePathOrURLpnpm test:int storage-s3pnpm test:int plugin-cloud-storagepnpm test:int uploads