feat: allow library asset url to be set and passed as a prop#613
Open
DNR500 wants to merge 1 commit into
Open
Conversation
* feat: library host url prefix prop added * feat: allow change of the full url using a url template
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
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.
Proposed Changes
Adds a
libraryAssetUrlTemplateprop to scratch-gui so embedders can control how library thumbnail URLs are built (sprite, costume, backdrop, and sound libraries).libraryAssetUrlTemplateprop on the GUI container/componentLibraryAssetConfigProvidercontext to pass the template into library modalsbuildLibraryAssetServiceUri()helper that substitutes{assetPath}into the templateThe template controls the full URL shape, not only the hostname. Embedders can match whatever asset API they run (path segments, trailing slashes, etc.), as long as they include the
{assetPath}placeholder where the asset id (and extension when needed) should go.Default (unchanged when the prop is omitted):
Example: asset
abc123with formatpng→{assetPath}becomesabc123.png:Example embedder override (same placeholder, different service shape):
→
https://assets.example.com/v1/library/abc123.pngWhen the prop is omitted, behaviour is unchanged and library assets still load from the standard Scratch CDN (
cdn.assets.scratch.mit.edu).Reason for Changes
Scratch is often embedded in other products (classroom platforms, LMSs, custom editors). Those hosts may need library assets served from their own infrastructure instead of the public Scratch CDN — for example:
Today, library thumbnail URLs are effectively fixed to the Scratch asset service. Project assets can already be configured by embedders via storage/host settings, but library browsing does not have an equivalent hook.
A URL template (rather than a fixed host or path prefix) lets each embedder align library requests with their own asset API contract while keeping scratch-gui agnostic of each host's URL layout. This change closes that gap with a small, optional prop and no impact on the default Scratch experience.
Test Coverage
Unit tests added for:
test/unit/lib/library-asset-url.test.js— URL building from templates,{assetPath}substitution, custom URL shapes, and default fallback to the MIT CDN templatetest/unit/contexts/library-asset-config-context.test.jsx— context provider supplies the template to consumers and falls back to the default when unset