Repository navigation
Upload Media: Public API for registering upload operations - #83331
Draft
swissspidy wants to merge 2 commits into
Draft
swissspidy wants to merge 2 commits into
swissspidy wants to merge 2 commits into
Conversation
registerUploadOperation, unregisterUploadOperation, getUploadOperation, getUploadOperations and registerUploadConcurrencyPool, wrapping the store's registry the way registerFormatType wraps the rich-text store. Each answers on the spot: a dispatched thunk only reports back through a promise, so the same checks the thunks run now live in one place and the public functions run them before dispatching anything that would not go through. Handlers and plans are handed a snapshot of their item rather than the queue's own record: the same File objects, the item's identity, and whatever earlier steps set aside, but none of the callbacks, the abort controller or the pipeline. The snapshot is frozen and additionalData is copied, so writing to it changes nothing; updates go through the result. The fields it carries are derived from the same list that decides what a result may set, so what a step may write, the next step may read. The README documents the contract and the architecture doc points at it. The API reference token now covers the package's index; docgen does not document TypeScript types, so the type exports show as undocumented, as they do in other packages. Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sr7G5nRsbso744zkruyGHZ
🤖 PR meta 🤖📦 Bundle sizeSize Change: +270 B (0%) Total Size: 8.21 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
|
A preview URL has to outlive the handler that made it: the editor shows it until the server's URL replaces it, so a handler cannot revoke it and a plugin had no way into the list the queue revokes with the item. context.createBlobURL( file ) creates the URL and records it against the item, the same way core's steps do by hand. A replacement of a core step receives the arguments core placed the step with, so UploadOperationArgs is exported and the README says which core steps take arguments, and that core/transcode-image is only placed when the site asks for a conversion. Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sr7G5nRsbso744zkruyGHZ
This branch has not been deployed
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?
See #82035. Step 2 of the rollout plan in #82035 (comment): the public API on top of the registry from #82474.
Stacked on #82474 — the diff here is only the public surface; the base branch is
try/82035-upload-queue-registryand will be retargeted totrunkonce that merges.Adds to
@wordpress/upload-media:registerUploadOperation( name, settings )unregisterUploadOperation( name )getUploadOperation( name )/getUploadOperations()registerUploadConcurrencyPool( name, { limit } )context.createBlobURL( file )on the handler contextUploadOperationType,UploadOperationArgsand theUploadOperation*types.Why?
#82474 rebuilt the queue on a registry but exposed nothing; core registers its steps through private store actions. This is the surface a plugin uses, shaped after
registerFormatType(): name first, settings second, an object back on success andundefinedplus a console error on rejection.Things the proposal specified differently from what the private contract had, settled here at the boundary:
Fileobjects, the item's identity (id,parentId,batchId), and whatever earlier steps set aside — but no callbacks, no abort controller, no pipeline. It's frozen andadditionalDatais copied, so writing to it changes nothing in the store; updates go through the handler's result. The fields it carries are derived fromPROTECTED_ITEM_KEYS, the same list that decides what a result may set, so what a step may write, the next step may read.updateProgressstays 0–100, which is what the store holds and the UI reads; the proposal's 0..1 was a sketch.Two additions that came out of the step-3 proofs of concept (#83333 in particular):
context.createBlobURL( file ). A preview URL has to outlive the handler — the editor shows it until the server's URL replaces it — so a handler cannot revoke it, and a plugin had no way into the list the queue revokes with the item. This creates the URL and records it against the item, the same thing core's steps do by hand with the privateCacheBlobUrlaction. Explicit rather than sniffingattachment.url, so it works for any field a plugin puts the URL in.UploadOperationArgsis exported and the README says which core steps take arguments, because a replacement of a core step receives the arguments core placed it with and has to understand them. The README also notes that core only placescore/transcode-imagewhen the site asks for a conversion, so a replacement meant to run on every image plans itself in.How?
The store's
dispatch()resolves through a promise, so a wrapper that merely dispatched the thunk could not return the registered operation synchronously the wayregisterBlockType()does. The checks the thunks run were extracted intostore/utils/registry.ts; the public functions run them first and dispatch only what will go through, and the thunks call the same helpers. One set of messages, two callers.snapshotItem()instore/utils/operations.tsbuilds the item snapshot;runOperationandplanOperationshand it to handlers and plans.createOperationContext()gainscreateBlobURL.The README gets an "Upload operations" section covering registration, planning, the handler contract, pools and core's operations, and the API reference token now covers the package index. docgen does not document TypeScript types, so the type exports appear as "Undocumented declaration.", as they do in
@wordpress/block-editorand others.Testing Instructions
npm run test:unit -- packages/upload-mediasrc/test/upload-operations.ts— the public functions against the default registry: register/get/unregister, the name argument winning oversettings.name, rejections returningundefinedwith the store's message, replacingcore/finalizeand putting it back, pool registration and an operation joining an unregistered pool.src/store/test/operations.ts— "hands the handler a snapshot of its item" (frozen; nostatus/operations/abortController/onSuccess; a write toadditionalDatadoes not reach the store), "hands a plan the same snapshot", and "revokes a blob URL a handler created when the item leaves".483 tests pass in
upload-media;npm run typecheck, eslint andlint:published-depsare clean.Testing Instructions for Keyboard
N/A — no UI changes.
Screenshots or screencast
N/A.
Use of AI Tools
Authored with Claude Code: the implementation, tests and this description. Design decisions (item snapshot, progress scale, sync registration via shared validation,
createBlobURLon the context) were reviewed and settled in discussion before implementation.🤖 Generated with Claude Code
https://claude.ai/code/session_01Sr7G5nRsbso744zkruyGHZ