feat(media): public media CRUD API routes (/api/media/v1)#68
Closed
ABB65 wants to merge 1 commit into
Closed
Conversation
The external media management surface external agents/CI use to upload
to Studio CDN and manage assets, built on the Phase 1 scope foundation.
- `server/utils/media-api.ts` — `resolveMediaApiContext`: the single gate
every route runs through (Bearer-key validation, project match, scope,
per-key hourly rate limit, plan feature, ee media provider; mirrors the
MCP Cloud proxy gate order; 503 in Community Edition).
- `server/utils/media-url.ts` — `withMediaUrls` decorates assets with the
CDN delivery URL + per-variant URLs (raw storage paths kept).
- Routes under `/api/media/v1/[projectId]/assets/`:
- GET `assets` (list, media:read), GET `assets/:id` (get, media:read)
- POST `assets` (upload, media:write) — multipart binary OR JSON {url}
(SSRF-guarded), shared validated pipeline + atomic storage reservation
- PATCH `assets/:id` (update meta), DELETE `assets/:id`, POST `assets/bulk`
(delete/tag, capped at 50, never cross-project) — all media:write
Only `upload` needs the file bytes (local → Local MCP/CI); list/get/
update/delete/bulk operate on ids + metadata, so they work over MCP Cloud
too. Helper unit tests cover the gate decisions + URL building (688 green).
Full per-route integration tests are a follow-up.
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.
Phase 2 — Public media CRUD API (
/api/media/v1/...)The external media management surface, built on the Phase 1 scope foundation (#67).
Routes —
/api/media/v1/[projectId]/assets/GET assetsmedia:readGET assets/:idmedia:readPOST assetsmedia:write{url}(SSRF-guarded)PATCH assets/:idmedia:writeDELETE assets/:idmedia:writePOST assets/bulkmedia:writeDesign
resolveMediaApiContext— one gate for every route: Bearer-key validation → project match → scope → per-key hourly rate limit → plan feature → ee media provider. Mirrors the MCP Cloud proxy gate order; 503 in Community Edition (no media provider).withMediaUrls— decorates assets with the CDN delivery URL + per-variant URLs (raw storage paths preserved). Public no-auth browser delivery via a custom domain stays ee/roadmap; this returns the Bearer-keyed/api/cdn/v1/...delivery URL.fetchRemoteMedia(URL mode) and the same MIME/size/storage-quota pipeline as the session route.Local-files note
Only
uploadneeds the file bytes → runs where the files are (Local MCP / CI).list/get/update/delete/bulkoperate on ids + metadata, so they work over MCP Cloud too.Tests
Unit tests for the gate (
resolveMediaApiContext: project match, scope, rate limit, provider-null) + URL building. 688 green (unit + integration + nuxt). Full per-route integration tests + the scope UI (CDNPanel) are follow-ups (Phase 3).