Add an image block to the page editor (#67) #72

Merged
miko merged 1 commit from feature/67-image-block into development 2026-11-04 12:03:21 +01:00
Owner

Closes #67

Summary

Admins insert images with an optional caption into a page's content. Each one is a Page Image: uncropped, in its own format, uploaded as soon as it is inserted.

insert image block (chosen, pasted or dropped)
  uploadPageImage                       # Server Action, admins only
    lock page → write original + WebP variants (no EXIF) → PageImage row
  block stores {imageId, caption}

savePage
  lock page → update content
  delete PageImages the content no longer references
  after the transaction: delete their files

deletePage
  lock page → delete page (PageImages cascade) → delete their files

GET /media/<id>/<variant>
  public + published → public, immutable
  internal           → signed-in only, private
  draft              → admins only
 prisma/schema.prisma
+  model PageImage {id, pageId → Page (cascade), fileKey, originalWidth, originalHeight}
 src/
 ├── contentPages/
+│   ├── imageActions.ts    # uploadPageImage
+│   ├── lockPage.ts
 │   └── actions.ts         # save/delete clean up page images
 ├── images/                # uncropped variants + upload, pageImageAccess
 └── richText/
+    ├── imageTool.ts       # Editor.js block; save waits for a running upload
     ├── document.ts        # image block (pages only), imageIds
     └── RichText.tsx       # <figure> with srcset; only the page's own images

Docs: the glossary entry Page Image, ADR 0005, 0006 and 0013 updated, and the CHANGELOG.

Evidence

  • Before: there was no image block; parseRichText dropped image blocks.
    After:
    • The parser round trip {type: "image", data: {imageId, caption}} stays as it is in pages; outside pages, or with invalid ids, the block is dropped.
    • pageImageAccess covers public, internal, draft and the original.
    • E2E an admin adds an image with a caption to a page…: it inserts a 900×300 image and checks that the variant stays 900×300 WebP. Draft: viewer gets 404, admin gets 200. Internal: guest gets 404, viewer gets 200 private. Public: guest gets 200 immutable. After the block is removed and the page saved: 404, and the variant files are gone.
    • The e2e test fails when the file cleanup is switched off.
  • Typecheck and lint are clean. 356 unit tests and 35 e2e tests pass.
  • Not yet tested by hand in the browser.

Merge Danger

Door: one-way (small)

The migration adds the PageImage table. Once page images have been saved, rolling back drops them, and the image blocks would simply no longer render.

Blast Radius: Pages

The page editor and page rendering, plus a new branch in /media. Guide, step and category editors are unchanged, and the parser drops image blocks there. Known limits:

  • Images uploaded and then abandoned without saving stay until the page is next saved.
  • When two tabs edit the same page, saving one can delete an image just uploaded in the other.

🤖 Generated with Claude Code

Closes #67 ## Summary Admins insert images with an optional caption into a page's content. Each one is a **Page Image**: uncropped, in its own format, uploaded as soon as it is inserted. ```text insert image block (chosen, pasted or dropped) uploadPageImage # Server Action, admins only lock page → write original + WebP variants (no EXIF) → PageImage row block stores {imageId, caption} savePage lock page → update content delete PageImages the content no longer references after the transaction: delete their files deletePage lock page → delete page (PageImages cascade) → delete their files GET /media/<id>/<variant> public + published → public, immutable internal → signed-in only, private draft → admins only ``` ```diff prisma/schema.prisma + model PageImage {id, pageId → Page (cascade), fileKey, originalWidth, originalHeight} src/ ├── contentPages/ +│ ├── imageActions.ts # uploadPageImage +│ ├── lockPage.ts │ └── actions.ts # save/delete clean up page images ├── images/ # uncropped variants + upload, pageImageAccess └── richText/ + ├── imageTool.ts # Editor.js block; save waits for a running upload ├── document.ts # image block (pages only), imageIds └── RichText.tsx # <figure> with srcset; only the page's own images ``` Docs: the glossary entry **Page Image**, ADR 0005, 0006 and 0013 updated, and the CHANGELOG. ## Evidence - **Before:** there was no image block; `parseRichText` dropped `image` blocks. **After:** - The parser round trip `{type: "image", data: {imageId, caption}}` stays as it is in pages; outside pages, or with invalid ids, the block is dropped. - `pageImageAccess` covers public, internal, draft and the original. - E2E `an admin adds an image with a caption to a page…`: it inserts a 900×300 image and checks that the variant stays 900×300 WebP. Draft: viewer gets 404, admin gets 200. Internal: guest gets 404, viewer gets 200 private. Public: guest gets 200 immutable. After the block is removed and the page saved: 404, and the variant files are gone. - The e2e test fails when the file cleanup is switched off. - Typecheck and lint are clean. 356 unit tests and 35 e2e tests pass. - Not yet tested by hand in the browser. ## Merge Danger **Door:** one-way (small) The migration adds the `PageImage` table. Once page images have been saved, rolling back drops them, and the image blocks would simply no longer render. **Blast Radius:** Pages The page editor and page rendering, plus a new branch in `/media`. Guide, step and category editors are unchanged, and the parser drops image blocks there. Known limits: - Images uploaded and then abandoned without saving stay until the page is next saved. - When two tabs edit the same page, saving one can delete an image just uploaded in the other. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Admins insert images into a page's content with an optional caption.
An image chosen, pasted or dropped is uploaded at once as a page image,
stored uncropped in its own format with WebP variants without EXIF, and
shown as wide as the text at most. The block stores only the page
image's id and the caption; saving waits for an upload still running.

Saving a page deletes the page images its content no longer shows,
files included, after the transaction; deleting a page deletes its
images' files too. Upload, save and delete lock the page row. The media
route serves page images by the page's visibility and status: public
and published for anyone, internal privately, drafts for admins only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
miko merged commit 13842949ee into development 2026-11-04 12:03:21 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MassiveDynamic/kataba!72
No description provided.