feat(pages): attach images to page comments
Summary
Comments on pages can carry up to four images: attach via button, paste, or drag onto the composer, on new threads and replies. Uploads start eagerly with per-image state; image-only comments are valid. Readers get inline thumbnails with a lightbox on desktop and web, mobile renders them in its comment sheets, and the CLI / MCP listings (per-page and org-wide) carry a fetchable URL per image — an agent reading a bug report can pull the screenshot.
No DB migration: the files library and the polymorphic attachments table already anticipated a comment parent, and the usercontent Worker already served /files/<id> behind signed tickets. This PR is that machinery's first producer:
pageComment.createImageUploadrecords a pending file and hands back a presigned PUT; bytes go client → R2, never through the API.- On create/reply the server verifies size, sniffs the bytes (stored type is what the bytes are, never the declaration; PNG/JPEG/GIF/WebP/AVIF only), and attaches + flips
pending → readyinside the comment's transaction, so ready ⇔ attached. Abandoned uploads sweep in a day. - Every response mints hour-windowed file tickets via new
MEDIA_URLenv; the media host serves without a database lookup. Access always derives from the comment's page. - Thread delete and page delete reap attachment rows, file rows, and R2 bytes via shared
detachAll/reapOrphanFiles— fixing in passing a pre-existing leak where page delete stranded staged page assets. ShapedComment.attachmentsis required (compile-time checklist across the four construction sites); read paths tolerate absence for old-API version skew.- Merged main's
pageComment.listForOrganizationand wired attachments through its join-based loading (same parameter-ceiling reasoning as its comments); added it to the public-access enumeration. Also seededSERVER_ANTHROPIC_API_KEYinto.env.local.example, which #7844 requires but never seeded — fresh worktrees fail setup without it.
Feature walkthrough with screenshots: https://app.superset.sh/page/images-in-page-comments-6ln0ic
Deploy prerequisite
Set the environment-scoped secret MEDIA_URL (Production: https://media.supersetusercontent.com; Preview: the media twin of Preview's USERCONTENT_URL) before merging — the API requires it at boot. The media host is already live on the Worker; desktop renderer PUTs to R2 are covered by #7864.
Test plan
- Integration suite against a real database (
packages/trpc/src/router/page-comment/attachments.integration.ts): sniff overrides a lying declaration; ticketed serve on create/reply/list; refuses non-image bytes, missing bytes, foreign uploads, double-attach; thread- and page-delete reap rows and bytes. - Unit tests: schema refinements (image-only comments, dedupe, caps), auth enumeration incl. the new procedures.
- Root typecheck (42 pkgs), lint,
check:i18n(7 new strings hand-translated into 16 locales). - Live CDP verification in the dev desktop app: pick/paste → eager upload → send → image re-served after full reload through a genuine ticket; lightbox open/close; zero console errors.
- After deploy: attach an image to a page comment in prod desktop and confirm it renders for a second org member.
Summary by cubic
Page comments now carry up to four images attached via picker, paste, or drag — image-only comments are valid (text is any non-empty body; only an empty body needs an image). Desktop/web show thumbnails with a lightbox; mobile renders them in comment sheets. Uploads start eagerly and the server sniffs bytes on create/reply (PNG/JPEG/GIF/WebP/AVIF only).
- Thread and page delete reap attachment rows, file rows, and R2 bytes — fixing a pre-existing leak where page delete stranded staged page assets. Thread delete reaps inside the delete transaction so a racing reply cannot orphan an image; page delete reaps staged assets even when version-object cleanup throws.
- The daily sweep now also drops
readyfiles nothing references, covering a reap whose object delete failed or whose process died before finishing; an hour of grace keeps an in-flight reap safe. - A failed post hands the composed images and text back to the composer; storage cleanup after a delete is logged, not surfaced. The composer accepts only the server's allowlist on pick/paste, image-only comments hide Edit (editing still requires text), and the sniffer treats unrecognized bytes as their declared type so unknown binary can't pass the image-only check.
No DB migration needed: the files library and polymorphic attachments table already anticipated a comment parent. Also seeds MEDIA_URL and SERVER_ANTHROPIC_API_KEY into .env.local.example, which #7844 requires but never seeded.
Migration
- Set the
MEDIA_URLenv secret before merging — the API requires it at boot.
Summary by CodeRabbit
- New Features
- Add up to four images to page comments and replies, including image-only comments. Preview images before posting, and select thumbnails to view them full size.
- Attach PNG, JPEG, GIF, WebP, or AVIF images up to 10 MB each.
- View attached images in comment listings, including in the command-line interface.
- Bug Fixes
- Restore comment text and attachments when submission fails.
- Avoid displaying empty comment text.
- Localization
- Add image-attachment controls and related messages across supported languages.