Skip to content

feat: a shared scene's link shows a frame of the scene and its title (D565) - #118

Merged
lnorton89 merged 5 commits into
masterfrom
feat/share-card
Nov 26, 2026
Merged

lnorton89 merged 5 commits into
masterfrom
feat/share-card

Conversation

@lnorton89

@lnorton89 lnorton89 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Pasted into a chat or a post, every /s/<id> link showed the sandbox's own card. Now it shows the scene.

  • Share sends a frame. cardFromCanvas (site/src/lib/play/card.ts) copies the canvas, crops the largest centred 1200x630 part, and encodes a JPEG under 160 KB, sent as card beside the scene.
  • The Worker keeps it beside the scene as cards/<id>.jpg (site/worker/share-card.ts). It is outside the content hash, so ids and old links are unchanged, and a scene keeps the first card it gets. Anything that is not a JPEG of the right size is dropped and the scene is still shared.
  • /s/<id> rewrites the page's social tags: the scene's title, its link, and /api/card/<id>.jpg when it has a card. A scene without one keeps the generic picture with its own title.

Decision D565; roadmap and site README updated (the README says how to delete a card with its scene).

Checked: site unit tests (340, including share-worker.test.ts, which drives the Worker's routes end to end against a fake bucket), tsc, eslint, and the conventions tests.

Not checked: the capture in a real browser, the full site build and Playwright smoke test, the deployed Worker, and a real link preview. Not deployed.

Update (from the bot review):

  • The size is now checked. Before, readCard checked only the JPEG's first and last bytes and its byte size. Now jpegSize walks the segment markers to the first frame header (SOF) and reads its height and width without decoding the picture, so only a 1200x630 JPEG is kept. The Worker's pixel constants are pinned to card.ts's by a test.
  • First-card-wins is documented as accepted in D565. Anyone who knows a scene's text can post it first with a picture of their own, and so can anyone for a scene shared before cards existed. Letting a later card replace one would open every link instead. The remedy is deleting cards/<id>.jpg.
  • Checked: 341 site unit tests, including new cases for wrong sizes, a progressive header, fill bytes, a DHT segment first, a scan before any header, and truncated segments. Also real sharp/libjpeg output, baseline and progressive (1200x630 kept, 800x600 dropped), plus tsc, eslint and the conventions tests.
  • CI's cargo-deny failure is not from this branch. It is RUSTSEC-2026-0543 (chrono unmaintained) and is fixed by fix: local time comes from jiff; chrono is unmaintained (D566) #120. Rerun after that merges.

…(D565)

Share sends a 1200x630 JPEG of the canvas beside the scene. The Worker keeps it as cards/<id>.jpg, outside the content hash, first card kept, and /s/<id> rewrites the /play page's og and twitter tags with the scene's title, its link and, when it has one, /api/card/<id>.jpg.
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @lnorton89's task in 19s —— View job


Review of #118

The change is correct and well-tested for what it covers. I found no rule violations: there is no unsafe and no unwrap, and the decision (D565) and roadmap entries are present. I read the code only and did not run the tests. I found two things worth a look.

1. First-card-wins can be squatted (site/worker/share-card.ts, storeCard; site/worker/index.ts, share)

  • Scene ids are content hashes, so anyone who knows a scene's content can compute its id.
  • Someone can POST that scene first with a misleading JPEG. The real owner's later card is then silently ignored, because storeCard returns false once a card exists.
  • This probably fits D565's threat model, since the scene text is public anyway. Say so in D565 explicitly if it is accepted. The alternative is to let a card replace the previous one only when none exists, which is the current behaviour.

2. The "right size" check is only a magic-byte check (readCard)

  • The PR description says anything that is not a JPEG "of the right size" is dropped.
  • The code checks the FF D8 FF header, the FF D9 trailer and the base64 length. It never checks the 1200x630 dimensions.
  • A client can store any JPEG up to 160 KB, for example a tiny or enormous-dimension image.
  • Parsing the SOF marker for width and height would enforce it cheaply. Otherwise, reword the description and the card.ts comments.

Minor

  • setMeta only matches <meta property|name=… content=…> in that attribute order. The comment says a changed page degrades gracefully, which is true, but the share-card test would silently stop covering it if Astro reorders the attributes. Check that the built /play/ HTML still matches. Your "not checked" list already includes the full build.

Summary: the change is sound, with the two points above. I left no inline comments.
· branch feat/share-card

Its Linux CUDA binary began answering 404 and failed npm ci. The site runs CLIP in the browser (D560) and never uses it; the CPU binaries are kept.
claude and others added 3 commits November 25, 2026 07:06
…00x630

readCard checked only a JPEG's first and last bytes and its byte size,
so any JPEG under 160 KB was kept, whatever its dimensions. jpegSize
walks the segment markers to the first SOF and reads its height and
width without decoding. D565 now also states that first-card-wins can
be claimed by anyone who knows a scene's text, and why it is accepted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W2BaQir6MZbp4JBpp3CZyT
@lnorton89
lnorton89 merged commit 3c49b93 into master Nov 26, 2026
10 checks passed
@lnorton89
lnorton89 deleted the feat/share-card branch November 26, 2026 21:52
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