Skip to content

feat(worker): guest transcript image upload + code block fixes#3

Open
wangjs-jacky wants to merge 1 commit into
PPsteven:mainfrom
wangjs-jacky:transcript-images
Open

feat(worker): guest transcript image upload + code block fixes#3
wangjs-jacky wants to merge 1 commit into
PPsteven:mainfrom
wangjs-jacky:transcript-images

Conversation

@wangjs-jacky

Copy link
Copy Markdown

Summary

Follow-up to the transcript publishing feature (#2). Adds guest image hosting for transcripts and fixes code-block rendering.

1. Guest image upload — POST /api/v1/transcript-image

Lets a transcript embed images that load same-origin over HTTPS. Previously a publisher had to reference images hosted elsewhere; if that host was HTTP or used an untrusted cert, browsers blocked them as mixed content and the images silently failed. Now images can be uploaded to the worker itself and served from /images/....

  • No auth (guest, same trust model as guest publish). Raw image bytes, mime via X-Image-Type (falls back to Content-Type). 5MB cap (413), non-image/empty (400).
  • Storage via a small imagesStore(env) adapter: uses R2 IMAGES when bound (unchanged behavior); falls back to PAGES_KV when no R2 is enabled (base64-wrapped), so the worker works on accounts without R2.
  • serveImage / handleUploadImage rewired through the same adapter — existing authed /api/v1/upload-image and existing images/... objects behave identically.

2. Code block fixes

  • <pre> now scrolls horizontally (overflow-x:auto, max-width:100%, white-space:pre) so long lines (e.g. shell scripts) don't break the layout; chat-theme bubble columns use minmax(0,1fr) + min-width:0 to stop wide code from overflowing the message column.
  • Fenced code no longer renders its language identifier as content: ```bash / ```json previously showed bash/json as the first line of the block. This also improves /api/v1/publish output (the only shared-render change).

Verification

Deployed to a test worker (KV-backed, no R2) and verified end-to-end: image upload → 201 same-origin URL → GET returns the exact bytes; transcript with a long bash block renders without a stray language line and scrolls instead of overflowing.

- Add POST /api/v1/transcript-image guest endpoint (no auth): accepts raw
  image bytes, mime from X-Image-Type (Content-Type fallback), 5MB cap
  (413), rejects non-image/empty (400), returns 201 with same-origin URL.
- Introduce imagesStore(env) adapter: R2 (env.IMAGES) when bound, else
  PAGES_KV fallback (img: prefixed keys, base64 value with chunked encode).
  Route authed /upload-image and serveImage through it (same backend,
  backward compatible for existing images/... keys).
- Fix code block styling in both document/chat themes: white-space:pre +
  overflow-x:auto horizontal scroll, max-width:100%, min-width:0; chat grid
  minmax(0,1fr), turn-body/markdown min-width:0, bubble overflow:hidden;
  inline code word-break; tab-size:2.
- Strip fence language identifier line in renderMarkdown so ```bash /
  ```json no longer render the language token as content.
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.

1 participant