Phase 14d-1: editor upload endpoint + FilePond vendoring#29
Merged
Conversation
Backend half of the upload pipeline: a JSON API mounted at
/editor/api/upload that wraps Phase 13's UploadHandler, persists the
file via the iManager 2.0 FileRepository + FileStorage, and emits a
matching <W>x<H>_<file> thumbnail next to the original via
ImageProcessor.
Editor\Api\UploadEndpoint:
POST multipart, fields {file, itemId, fieldId, tokenName, tokenValue}
→ 200 {fileId, name, url, mime, size, width, height,
thumbnailUrl?}
→ 400 / 403 / 401 / 405 with {"error":"..."}
DELETE form-urlencoded body {fileId, tokenName, tokenValue} (also
accepts FilePond's `revert` raw-body shape)
→ 200 {"status":"ok"} (removes thumbnail siblings best-effort)
EditorRouter intercepts /editor/api/* before any other module:
- anonymous → 401 JSON (XHR-friendly, not a 302 redirect)
- logged-in → dispatchApi() → UploadEndpoint::handle($method)
- non-`upload` resource → 404 JSON
CSRF tokens are validated per request; the /editor/pages form's
"pages" token is what FilePond will submit in 14d-2.
FilePond vendoring under editor/theme/scripts/filepond/ (~170 KB):
- filepond.{js,css} (4.32.7)
- filepond-image-preview.{js,css} (4.6.12)
- filepond-file-validate-type.js (1.2.9)
- filepond-file-validate-size.js (2.2.8)
The actual <script> wiring + page-edit form integration ships in 14d-2.
Manual smoke (PHP built-in server, 64×64 PNG fixture):
POST upload (image) → 200 JSON; files row + asset on disk
GET thumbnailUrl → 200 image (300×300 generated)
DELETE fileId → 200; files row gone, asset gone
POST without CSRF → 403 {"error":"CSRF token invalid"}
POST anonymous → 401 {"error":"Authentication required"}
POST 11 MB binary → 400 {"error":"... max allowed is 10485760"}
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.
Summary
Backend half of the upload pipeline: a JSON API mounted at
/editor/api/uploadthat wraps Phase 13'sUploadHandler, persiststhe file via the iManager 2.0
FileRepository+FileStorage, andemits a matching
<W>x<H>_<file>thumbnail next to the original viaImageProcessor.Editor\Api\UploadEndpoint:{file, itemId, fieldId, tokenName, tokenValue}→ 200
{fileId, name, url, mime, size, width, height, thumbnailUrl?}→ 400 / 403 / 401 / 405 with
{"error":"..."}{fileId, tokenName, tokenValue}(also accepts FilePond's
revertraw-body shape)→ 200
{"status":"ok"}(removes thumbnail siblings best-effort)EditorRouterintercepts/editor/api/*before any other module:dispatchApi()→UploadEndpoint::handle($method)uploadresource → 404 JSONCSRF tokens are validated per request; the /editor/pages form's
"pages" token is what FilePond will submit in 14d-2.
FilePond vendoring under
editor/theme/scripts/filepond/(~170 KB):filepond 4.32.7, image-preview 4.6.12, file-validate-type 1.2.9,
file-validate-size 2.2.8. Form integration ships in 14d-2.
Test plan
{"error":"CSRF token invalid"}{"error":"Authentication required"}