docs(37-04): add Plan 37-04 summary for Journal Media Library unification
This commit is contained in:
90
.planning/phases/37-media-library-album/37-04-SUMMARY.md
Normal file
90
.planning/phases/37-media-library-album/37-04-SUMMARY.md
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
---
|
||||||
|
phase: 37-media-library-album
|
||||||
|
plan: 04
|
||||||
|
subsystem: journal-media-unification
|
||||||
|
tags: [sm-journal-plugin, vue-journal-layer, album, srcset, blogeditor, media-picker, sanitize-html]
|
||||||
|
requires: ["37-02", "37-03"]
|
||||||
|
provides:
|
||||||
|
- "`sm-journal-plugin` `POST /_journal/api/v1/media/upload` and Blog Editor direct uploads unified onto `modules/album` (virtual folder `journal` + sanitized subfolders), preserving `{data: {url, path}}` and additively returning `id`, `short_id`, `width`, `height`, `variants`, and `srcset` (D-13)"
|
||||||
|
- "Single-query batched render-time `srcset`/`sizes`/`width`/`height` enrichment (`classes.ExtractMediaShortIDs`, `classes.EnrichMediaHTML`) across `Index`, `Show` (+ `related_posts`), `Store`, `Update`, and `AuthorPosts` without mutating stored DB HTML and leaving legacy `/uploads/...` images byte-identical (D-14)"
|
||||||
|
- "Blog Editor \"Choose from Media Library\" toolbar action (`summer-media-pick` / `summer-media-pick-result`) wired to the host admin `MediaPickerModal` via `PluginField.vue`, inserting clean `<img src=\"/media/...\" alt=\"...\" width=\"...\" height=\"...\">` (D-05)"
|
||||||
|
- "`vue-journal-layer` `sanitizeJournalHtml` / `gateJournalHtml` allow-list permitting validated `srcset`, `sizes`, `width`, `height`, `loading`, and `decoding` on `<img>` while stripping unsafe schemes (`javascript:`, `data:`, `vbscript:`, `mailto:`) and invalid descriptors (D-14)"
|
||||||
|
affects:
|
||||||
|
- "../sm-journal-plugin"
|
||||||
|
- "../vue-journal-layer"
|
||||||
|
- "admin/src/components/form"
|
||||||
|
- "modules/boardwalk/dist"
|
||||||
|
key-files:
|
||||||
|
created:
|
||||||
|
- "../sm-journal-plugin/classes/enrich_media.go"
|
||||||
|
- "../sm-journal-plugin/classes/enrich_media_test.go"
|
||||||
|
modified:
|
||||||
|
- "../sm-journal-plugin/controllers/api/media.go"
|
||||||
|
- "../sm-journal-plugin/controllers/api/posts.go"
|
||||||
|
- "../sm-journal-plugin/controllers/api/authors.go"
|
||||||
|
- "../sm-journal-plugin/classes/blog_editor.go"
|
||||||
|
- "../sm-journal-plugin/assets/src/blogeditor/element.ts"
|
||||||
|
- "../sm-journal-plugin/assets/src/blogeditor/extensions.ts"
|
||||||
|
- "../sm-journal-plugin/assets/src/blogeditor/labels.ts"
|
||||||
|
- "../sm-journal-plugin/assets/src/blogeditor/toolbar.ts"
|
||||||
|
- "../sm-journal-plugin/assets/dist/blogeditor.js"
|
||||||
|
- "../sm-journal-plugin/journal_api_task3_test.go"
|
||||||
|
- "../sm-journal-plugin/tests/blogeditor/element.test.ts"
|
||||||
|
- "../sm-journal-plugin/README.md"
|
||||||
|
- "../vue-journal-layer/app/utils/htmlGate.ts"
|
||||||
|
- "../vue-journal-layer/tests/htmlGate.test.ts"
|
||||||
|
- "admin/src/components/form/formContext.ts"
|
||||||
|
- "admin/src/components/form/fields/PluginField.vue"
|
||||||
|
- "modules/boardwalk/dist/"
|
||||||
|
key-decisions:
|
||||||
|
- "Added `summer-media-pick` / `summer-media-pick-result` custom DOM event bridge in `admin/src/components/form/PluginField.vue` wrapping the shared `MediaPickerModal.vue` so the Blog Editor custom element never handles credentials directly and stays consistent with `summer-upload`."
|
||||||
|
- "Preserved raw `srcset` in `vue-journal-layer`'s `KEEP_ALL` reference sanitizer pass via a temporary attribute rewrite so `sanitize-html`'s built-in `srcset` URL filter cannot distort `gateJournalHtml` safe/unsafe comparisons."
|
||||||
|
- "Kept `classes.StoreMedia` fallback in `uploadBlogImage` when `*gorm.DB` is absent on `app` so existing bucket-only unit tests in `sm-journal-plugin` remain green while real admin uploads store into `modules/album`."
|
||||||
|
completed: 2026-11-27
|
||||||
|
---
|
||||||
|
|
||||||
|
# Phase 37 Plan 04: Journal Media Unification, Inline `srcset` Enrichment & Blog Editor Picker Summary
|
||||||
|
|
||||||
|
**Unified `sm-journal-plugin` media uploads onto `modules/album`, added single-query batched inline WebP `srcset`/`sizes` enrichment during post API serialization, wired the Blog Editor's "Choose from Media Library" action to the shared admin `MediaPickerModal`, and updated `vue-journal-layer`'s `sanitize-html` allow-list to preserve safe responsive image attributes.**
|
||||||
|
|
||||||
|
## Commits
|
||||||
|
|
||||||
|
- `../sm-journal-plugin`: `ccd8dc8` — `feat(media): unify uploads onto modules/album, add batched srcset enrichment and Media Library picker`
|
||||||
|
- `../vue-journal-layer`: `2dcd443` — `feat(sanitizer): allow safe srcset, sizes, loading, and decoding on inline img elements`
|
||||||
|
- `summercms.go`: `6e447143` — `feat(admin): wire summer-media-pick MediaPickerModal event in PluginField and rebuild boardwalk dist`
|
||||||
|
|
||||||
|
## What Was Built
|
||||||
|
|
||||||
|
1. **`sm-journal-plugin` `modules/album` Upload Unification & Batched `srcset` Enrichment**:
|
||||||
|
- Updated `controllers/api/media.go` (`POST /_journal/api/v1/media/upload`) and `classes/blog_editor.go` (`uploadBlogImage`) to store new uploads via `modules/album` into the virtual folder `journal` (plus any sanitized subfolder via `classes.EnsureJournalMediaFolder`). Preserved `{data: {url, path}}` and 422 validation bodies while additively returning `id`, `short_id`, `width`, `height`, `variants`, and `srcset`.
|
||||||
|
- Added `classes/enrich_media.go` (`ExtractMediaShortIDs`, `ExtractMediaShortIDsWithConfig`, `EnrichMediaHTML`, `EnsureJournalMediaFolder`) and `classes/enrich_media_test.go`. `EnrichMediaHTML` rewrites only matching `<img src="/media/<short-id>/...">` tags to add `srcset`, `sizes="(max-width: 768px) 100vw, 800px"`, and `width`/`height` (when absent), leaving legacy `/uploads/...` and external images byte-identical.
|
||||||
|
- Updated `controllers/api/posts.go` (`Index`, `Show`, `Store`, `Update`) and `controllers/api/authors.go` (`AuthorPosts`) to batch-load all referenced `/media/<short-id>/...` items across posts, translations, and related posts in a single `album.Service.GetItemsByShortIDs` (`WHERE short_id IN ?`) query per request without mutating stored DB rows.
|
||||||
|
- Documented `album` backing and render-time `srcset` enrichment in `../sm-journal-plugin/README.md`.
|
||||||
|
|
||||||
|
2. **Blog Editor Media Library Picker & `PluginField.vue` Bridge**:
|
||||||
|
- Added `FIELD_MEDIA_PICK_EVENT` (`summer-media-pick`) and `FIELD_MEDIA_PICK_RESULT_EVENT` (`summer-media-pick-result`) in `admin/src/components/form/formContext.ts` and wired `<MediaPickerModal>` into `admin/src/components/form/fields/PluginField.vue`. Rebuilt `modules/boardwalk/dist`.
|
||||||
|
- Added the "Choose from Media Library" toolbar button (`Library`, EN/PL labels) and `SizedImage` (`width`/`height` attribute support) in `../sm-journal-plugin/assets/src/blogeditor/`, rebuilt `assets/dist/blogeditor.js`, and added a Vitest test in `tests/blogeditor/element.test.ts`.
|
||||||
|
|
||||||
|
3. **`vue-journal-layer` `sanitize-html` Responsive Image Allow-List**:
|
||||||
|
- Updated `../vue-journal-layer/app/utils/htmlGate.ts` to allow `srcset` (strictly validated per comma-separated `<url> [<descriptor>]` candidate; relative or `http:`/`https:` only, rejecting `javascript:`, `data:`, `vbscript:`, `mailto:`), `sizes` (safe CSS media/length characters, rejecting `url()`/`expression()`), `loading` (`lazy|eager`), and `decoding` (`async|sync|auto`) alongside existing `width`/`height` on `<img>`.
|
||||||
|
- Added sanitizer unit tests in `../vue-journal-layer/tests/htmlGate.test.ts`.
|
||||||
|
|
||||||
|
## Verification Results
|
||||||
|
|
||||||
|
All verification commands passed green (with `../sm-journal-plugin/go.mod` left untouched and zero release tags created):
|
||||||
|
|
||||||
|
- Temporary `GOWORK` (`go 1.27.0` pointing to local `summercms.go` + `sm-journal-plugin`):
|
||||||
|
- `go -C ../sm-journal-plugin vet ./...` — passed
|
||||||
|
- `go -C ../sm-journal-plugin test -short ./...` — passed across all packages
|
||||||
|
- `npm --prefix ../sm-journal-plugin run build` — passed (`assets/dist/blogeditor.js` rebuilt)
|
||||||
|
- `npm --prefix ../sm-journal-plugin test` — passed (10/10 test files, 258/258 tests)
|
||||||
|
- `(cd ../sm-journal-plugin && bash scripts/check-dist.sh)` — `check-dist: assets/dist matches a fresh build`
|
||||||
|
- `npm --prefix ../vue-journal-layer test` — passed (204/204 tests)
|
||||||
|
- `npm --prefix admin run typecheck` — passed (`vue-tsc --noEmit`)
|
||||||
|
- `npm --prefix admin run test` — passed (120/120 test files)
|
||||||
|
- `npm --prefix admin run build` & `scripts/check-admin-dist.sh` — `check-admin-dist: modules/boardwalk/dist matches a fresh build`
|
||||||
|
|
||||||
|
## Deviations from Plan
|
||||||
|
|
||||||
|
- Wired the `summer-media-pick` / `summer-media-pick-result` modal bridge in `summercms.go`'s `admin/src/components/form/PluginField.vue` (and rebuilt `modules/boardwalk/dist`) so the Blog Editor reuses the exact shared `MediaPickerModal.vue` component from Plan 37-03 without holding credentials in the custom element.
|
||||||
|
- Also added single-query batched `srcset` enrichment to `AuthorPosts` (`controllers/api/authors.go`), `Store`, and `Update` in addition to `Index` and `Show` so every post-serializing Journal API endpoint behaves consistently.
|
||||||
Reference in New Issue
Block a user