Skip to content

fix: use a catch-all media route for slashed storage keys - #182

Merged
ascorbic merged 4 commits into
emdash-cms:mainfrom
masonjames:codex/media-route-catchall
Apr 11, 2026
Merged

fix: use a catch-all media route for slashed storage keys#182
ascorbic merged 4 commits into
emdash-cms:mainfrom
masonjames:codex/media-route-catchall

Conversation

@masonjames

@masonjames masonjames commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the injected Astro media route to use a catch-all path so storage keys containing slashes resolve correctly.

It also adds route-level tests that verify slashed keys reach the handler intact and that missing keys return 404 cleanly.

Type of change

  • Bug fix
  • Feature (requires approved Discussion)
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm --silent lint:json | jq '.diagnostics | length' returns 0
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/...

AI-generated code disclosure

  • This PR includes AI-generated code

Screenshots / test output

  • pnpm --silent lint:quick
  • pnpm --filter emdash exec vitest run tests/unit/astro/routes.test.ts
  • pnpm typecheck
  • pnpm --silent lint:json | jq '.diagnostics | length'
@changeset-bot

changeset-bot Bot commented Apr 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c870759

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/plugin-ai-moderation Patch
@emdash-cms/plugin-atproto Patch
@emdash-cms/plugin-audit-log Patch
@emdash-cms/plugin-color Patch
@emdash-cms/plugin-embeds Patch
@emdash-cms/plugin-forms Patch
@emdash-cms/plugin-webhook-notifier Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@masonjames
masonjames marked this pull request as ready for review April 5, 2026 17:02
Copilot AI review requested due to automatic review settings April 5, 2026 17:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the injected Astro media route to use a catch-all parameter so storage keys containing / resolve correctly, and adds unit tests to validate behavior.

Changes:

  • Update core route injection to mount the media file endpoint as /_emdash/api/media/file/[...key].
  • Add a new catch-all media file API handler that serves files from storage using the full slashed key.
  • Add Vitest coverage for route injection and for slashed/missing keys.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
packages/core/src/astro/integration/routes.ts Switches injected media file route from single-segment [key] to catch-all [...key].
packages/core/src/astro/routes/api/media/file/[...key].ts Implements GET handler for serving files by catch-all storage key (supports slashes).
packages/core/tests/unit/astro/routes.test.ts Adds tests ensuring the injected route uses [...key] and that slashed/missing keys behave correctly.
.changeset/blue-poems-laugh.md Adds a patch changeset describing the bug fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ascorbic
ascorbic enabled auto-merge (squash) April 11, 2026 09:18
@pkg-pr-new

pkg-pr-new Bot commented Apr 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@182

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@182

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@182

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@182

emdash

npm i https://pkg.pr.new/emdash@182

create-emdash

npm i https://pkg.pr.new/create-emdash@182

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@182

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@182

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@182

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@182

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@182

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@182

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@182

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@182

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@182

commit: c870759

@ascorbic
ascorbic merged commit 156ba73 into emdash-cms:main Apr 11, 2026
25 checks passed
This was referenced Apr 11, 2026
@masonjames
masonjames deleted the codex/media-route-catchall branch April 13, 2026 15:02
fmhall pushed a commit to fmhall/emdash that referenced this pull request Apr 13, 2026
…#182)

* fix media route for slashed storage keys

* chore: add changeset for media route catch-all

---------

Co-authored-by: Matt Kane <mkane@cloudflare.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment