Skip to content

feat(demo): shareable URL state — ?source=<url>&q=<preset>&f=<format>#8

Closed
klappy wants to merge 1 commit into
feat/click-to-zoom-modalfrom
feat/shareable-url-source
Closed

feat(demo): shareable URL state — ?source=<url>&q=<preset>&f=<format>#8
klappy wants to merge 1 commit into
feat/click-to-zoom-modalfrom
feat/shareable-url-source

Conversation

@klappy
Copy link
Copy Markdown
Owner

@klappy klappy commented May 27, 2026

Why

The demo page is genuinely useful when someone — a person, Aquifer, an LLM, an integration partner — can deep-link to it with their own image. Right now you have to load the page and paste a URL. With this change, the page reads its source from ?source=<url> and any external system can produce shareable links like:

https://transcode-mcp.klappy.workers.dev/?source=https://aquifer.klappy.dev/api/images/abc123
https://transcode-mcp.klappy.workers.dev/?source=https://example.com/photo.jpg&q=high&f=avif

The page URL itself becomes the shareable state. Round-trips work even when the source URL has its own query string (Unsplash ?w=2000, signed URLs, etc.).

How It Works

  • On load: parse ?source=, ?q=, ?f= from the page URL and populate the controls. If the source matches one of the dropdown options exactly, it gets selected; otherwise it goes in the custom URL field. The page then loads the grid with that source.
  • On control change: write the current control state back to the URL via history.replaceState (not pushState, so the back button still works normally — no per-change history pollution).
  • Share-link button: copies the current URL with the modern Clipboard API; falls back to execCommand then to window.prompt for environments where clipboard access is blocked. Shows a toast confirmation either way.
  • Defaults stay clean: q=medium and f=auto don't get written to the URL because they're the defaults — keeps shared links short and human-readable.

Aquifer integration

This enables the use case you mentioned: Aquifer or any system pointing at a UBSImages-style image catalog can construct a transcode-mcp link by URL-encoding the source URL into ?source=. The Cloudflare worker's URL parser (fixed in PR #7 for embedded query strings) handles the resulting nested encoding correctly.

Branch base

This PR branches off feat/click-to-zoom-modal (PR #7) because it depends on the demo page changes there. After PR #7 merges, GitHub will auto-update this PR's base to main.

Tests

No new tests — this is pure frontend state plumbing. Round-trip verification done via Node script:

source: https://images.unsplash.com/photo-X?w=2000
→ ?source=https%3A%2F%2Fimages.unsplash.com%2Fphoto-X%3Fw%3D2000
→ parsed back to same source: ✓

Existing 29/29 tests still pass. Typecheck clean.


Note

Low Risk
Frontend-only demo HTML/JS with no server, auth, or data-path changes.

Overview
Adds shareable URL state to the demo page so ?source=, ?q=, and ?f= deep-link to the same source, quality, and format as the controls. On load, query params populate the dropdown or custom URL field; on control changes, history.replaceState keeps the address bar in sync (default medium / auto are omitted from the URL).

A Share link secondary button syncs state, copies the current page URL via the Clipboard API with execCommand / prompt fallbacks, and shows a toast for confirmation. Styling adds btn-secondary and toast visibility transitions; the custom URL placeholder notes the ?source= option.

Reviewed by Cursor Bugbot for commit 95431f6. Bugbot is set up for automated code reviews on this repo. Configure here.

The demo page now reads its state from the URL query string and writes
it back when controls change. Anyone (Aquifer, an LLM, a person) can
deep-link to a specific view of a specific source image:

  /?source=https://aquifer.klappy.dev/api/images/abc123
  /?source=https://example.com/photo.jpg&q=high&f=avif

The page URL itself becomes the shareable state. A Share-link button
copies the current URL to the clipboard with a toast confirmation,
using the modern Clipboard API with execCommand fallback and prompt as
a last resort.

Round-trip works correctly with source URLs that contain their own
query strings (Unsplash ?w=2000, signed URLs, etc.) because
URLSearchParams handles the nested encoding cleanly.

Implementation:
- readUrlState() parses source/q/f from window.location.search
- writeUrlState() rebuilds the query string from current control state
  and uses history.replaceState (not pushState) so the back button
  still works as expected
- applyUrlState() runs on load: if the source matches a dropdown
  option exactly, it'\''s selected; otherwise it goes in the custom
  URL field. Quality and format are restored if present.
- writeUrlState() runs after every control change and once after
  initial load (so defaults like q=medium don'\''t pollute the URL)
- Share-link button copies current URL with clipboard API + fallbacks

The placeholder on the custom URL field now mentions the ?source=
shortcut so users discover the feature.

No proxy changes. Tests still 29/29.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
transcode-mcp 95431f6 Commit Preview URL

Branch Preview URL
May 27 2026, 09:54 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants