docs(37-01): add Plan 37-01 execution summary
This commit is contained in:
95
.planning/phases/37-media-library-album/37-01-SUMMARY.md
Normal file
95
.planning/phases/37-media-library-album/37-01-SUMMARY.md
Normal file
@@ -0,0 +1,95 @@
|
||||
---
|
||||
phase: 37-media-library-album
|
||||
plan: 01
|
||||
subsystem: media-library
|
||||
tags: [album, lagoon, surf, webp, media, migrations, docs]
|
||||
requires: []
|
||||
provides:
|
||||
- "Core `modules/album` package (schema, models, migrations, service, WebP variants, single-use upload tokens, Mail Images backfill, HTTP handlers)"
|
||||
- "`summercms.album` migration set wired into `modules/lagoon/migrations.go`"
|
||||
- "Zero-DB-hit `/media/{short_id}/{file}` static serving and raw `PUT`/`POST /media/upload/{token}` signed upload routes wired into `modules/surf`"
|
||||
- "Module README (`modules/album/README.md`), root `README.md` table row, and `docs/services/media-library.md`"
|
||||
affects:
|
||||
- "modules/album"
|
||||
- "modules/lagoon"
|
||||
- "modules/surf"
|
||||
- "docs/services/media-library.md"
|
||||
tech-stack:
|
||||
added: []
|
||||
patterns:
|
||||
- "Zero-cycle core module (`modules/album` imports `lagoon/attach` and `lagoon/attach/webp`, never `modules/lagoon`)"
|
||||
- "Immutable `media/<short-id>/<slug>.<ext>` blob keys with synchronous non-upscaling WebP `480w`/`960w`/`1600w` variants"
|
||||
- "Atomic single-use DB-backed upload tokens (`UPDATE ... WHERE token_hash = ? AND used_at IS NULL AND expires_at > NOW() RETURNING ...`)"
|
||||
- "Transactional delete seam (`DeleteItemInTx` + `DeleteBlobs`) for `lagoon.AfterCommit` cleanup"
|
||||
key-files:
|
||||
created:
|
||||
- modules/album/album.go
|
||||
- modules/album/models.go
|
||||
- modules/album/migrations.go
|
||||
- modules/album/variants.go
|
||||
- modules/album/service.go
|
||||
- modules/album/tokens.go
|
||||
- modules/album/backfill.go
|
||||
- modules/album/http.go
|
||||
- modules/album/album_smoke_test.go
|
||||
- modules/album/example_test.go
|
||||
- modules/album/README.md
|
||||
- modules/surf/media.go
|
||||
- docs/services/media-library.md
|
||||
modified:
|
||||
- modules/lagoon/migrations.go
|
||||
- modules/surf/router.go
|
||||
- README.md
|
||||
- docs/index.md
|
||||
key-decisions:
|
||||
- "Used `VARCHAR(64) NOT NULL DEFAULT ''` for `summer_media_items.sha256` so legacy backfilled rows do not get space-padded by Postgres `CHAR(64)` while uploaded items store exact 64-char lowercase SHA-256 hex."
|
||||
- "In `surf.mountMedia`, when `media.serve` is unset and only inherited from `storage.uploads.serve`, avoid colliding if the app explicitly set `storage.uploads.public_path_prefix` to `/media`, and only mount signed upload routes when `app.Config` has media/uploads/backend/MCP active so bare test routers keep their exact route list."
|
||||
- "Updated `docs/index.md` instead of `docs/README.md` (which does not exist in this repository)."
|
||||
patterns-established:
|
||||
- "`album.Install(app)` / `album.ServiceFrom(app)` for app-scoped media library access across `surf`, `cabana`, `pier`, and plugins."
|
||||
duration: 13m
|
||||
completed: 2026-11-27
|
||||
---
|
||||
|
||||
# Phase 37 Plan 01: Core `modules/album` Media Library Summary
|
||||
|
||||
**Built and wired the core `modules/album` Media Library module end to end — Postgres migrations in `lagoon`, synchronous WebP `srcset` variants, single-use signed upload tokens, after-commit delete seam, Mail Images backfill, zero-DB-hit `/media/...` serving in `surf`, smoke tests, and verified docs.**
|
||||
|
||||
## Commits
|
||||
|
||||
- `cff3e34e` — `feat(album): add core Media Library module, migrations, and surf routes`
|
||||
|
||||
## What Was Built
|
||||
|
||||
1. **Core Schema, Models & Migrations (`modules/album/album.go`, `models.go`, `migrations.go`, `modules/lagoon/migrations.go`)**:
|
||||
- Exported config keys (`media.max_bytes`, `media.base64_max_bytes`, `media.public_path_prefix`, `media.serve`) and `album.Install` / `album.ServiceFrom` helpers.
|
||||
- Defined `Folder`, `Variant`, `Variants` (Postgres JSONB `Valuer`/`Scanner`), `Item` (`IsImage`, `PublicURL`, `AbsolutePublicURL`, `Srcset`, `AllBlobKeys`), and `UploadToken`.
|
||||
- Added `album.Migrations` creating `summer_media_folders`, `summer_media_items`, and `summer_media_upload_tokens` with all required unique constraints, FKs, and indexes, and registered `{"summercms.album", "media", album.Migrations}` in `modules/lagoon/migrations.go` without any circular import.
|
||||
|
||||
2. **Upload Pipeline, WebP Variants, Tokens & Backfill (`modules/album/service.go`, `variants.go`, `tokens.go`, `backfill.go`)**:
|
||||
- `Service.Upload` reuses `attach.DefaultImageExtensions`, `attach.DefaultFileExtensions`, `attach.IsAllowedImage`, `attach.DiskExtension`, and `attach.UploadWriterOptions`, explicitly rejecting SVG, HTML, and JS, computing streaming SHA-256 without deduplication, writing to `media/<short-id>/<slug>.<ext>`, generating synchronous non-upscaling WebP `480w`/`960w`/`1600w` variants via `lagoon/attach/webp` + `golang.org/x/image/draw`, and cleaning up all written blobs on any error.
|
||||
- Folder CRUD (`EnsureFolder`, `ListFolders`, `CreateFolder`, `UpdateFolder`, `DeleteFolder` with `ErrFolderNotEmpty`), item queries (`ListItems`, `GetItem`, `GetItemsByShortIDs` batched lookup, `UpdateItem`), and transactional delete seam (`DeleteItemInTx` + `DeleteBlobs`).
|
||||
- Single-use upload tokens (`PrepareUpload` storing only SHA-256 hash with 5-min default TTL; `ConsumeUploadToken` atomically updating `used_at = NOW()` via `UPDATE ... RETURNING`).
|
||||
- Idempotent `BackfillMailImages` indexing legacy `System\Models\MailImageLibrary` rows into virtual folder `mail` via `legacy_file_id` while preserving existing `/uploads/...` URLs.
|
||||
|
||||
3. **HTTP Handlers, `surf` Mounting, Smoke Tests & Docs (`modules/album/http.go`, `modules/surf/media.go`, `modules/surf/router.go`, `album_smoke_test.go`, `example_test.go`, `modules/album/README.md`, `README.md`, `docs/services/media-library.md`, `docs/index.md`)**:
|
||||
- `StaticHandler` serves `GET`/`HEAD /media/{short_id}/{file}` with zero DB hits, strict segment validation, `Cache-Control: public, max-age=31536000, immutable`, `X-Content-Type-Options: nosniff`, sandboxing CSP, and `Content-Disposition: attachment` for non-inline types.
|
||||
- `SignedUploadHandler` serves raw `PUT`/`POST /media/upload/{token}` with atomic token consumption and `http.MaxBytesReader`.
|
||||
- `surf.BuildRouter` calls `mountMedia(r, app)` right after `mountUploads(r, app)`, publishing `*album.Service` and mounting the static and throttled (`throttle:60,1`) upload routes.
|
||||
- Added `memblob` smoke tests, compiled `example_test.go` snippets, `modules/album/README.md` with `**Name:**` mnemonic, root `README.md` module row, and `docs/services/media-library.md`.
|
||||
|
||||
## Verification Results
|
||||
|
||||
All checks passed after the final edit:
|
||||
|
||||
- `go run ./cmd/summer docs:sync` — `updated 6 snippets in 2 files`
|
||||
- `go vet ./...` — passed (0 warnings/errors)
|
||||
- `go test -short ./...` — passed across all packages (`modules/album`, `modules/surf`, `modules/lagoon`, `cmd/summer`, etc.)
|
||||
- `go test ./cmd/summer -run TestDocsTree` — passed
|
||||
- `go run ./cmd/summer docs:build --check` — `docs:build: no problems found`
|
||||
|
||||
## Deviations from Plan
|
||||
|
||||
- **Docs index path**: Plan listed `docs/README.md`, which does not exist in this repository; linked `services/media-library.md` in `docs/index.md` instead.
|
||||
- **`surf.mountMedia` compatibility guard**: Added a guard when `media.serve` is only inherited from `storage.uploads.serve` so an explicit `storage.uploads.public_path_prefix: "/media"` (tested by `TestUploadsMount`) does not collide, and only mounted signed upload routes when `app.Config` has media/uploads/backend/MCP configured so bare routers (`ExampleBuildRouter`, `ExampleAssembleRouter`, `TestRouteListJSON`) retain their exact route lists.
|
||||
- **`sha256` column type**: Used `VARCHAR(64) NOT NULL DEFAULT ''` instead of `CHAR(64)` so legacy backfilled rows are not space-padded by Postgres.
|
||||
Reference in New Issue
Block a user