Repository navigation
feat: Danbooru-style uploader, unrated rating, post metadata editing + upload event - #12
Conversation
…+ upload event Reworks the upload flow to match Danbooru (selecting a file uploads immediately with progress; metadata is edited on the created post), adds an `unrated` default rating, post-metadata editing, a Core event bus for upload hooks, and assorted web-layout polish. Core / data: - rating enum gains `unrated` and defaults to it (a fresh upload is unrated until classified). Two-step migration (ALTER TYPE ADD VALUE, then SET DEFAULT) so the new value commits before it's used; verified on a fresh DB. - AssetRepository.update + AssetService.update (mutable: rating, source). - Search compiler accepts `rating:unrated`. - @bunbooru/events: a generic, dependency-free TypedEventEmitter (fire-and-forget, error-isolated). Core defines `asset.created` and emits it on a NEW upload — the hook future plugins (auto-tag, similar-finder, thumbnails, OCR) subscribe to (CLAUDE.md Event Rule). Unit-tested. API: - POST /api/v1/assets accepts `source`; rating union includes `unrated`. - New PATCH /api/v1/assets/:id (rating, source). Shared rating/id/source schemas. - Tests for PATCH (forward/404/unrated/invalid). Web: - Two-stage uploader: pick/drop → immediate upload with a progress bar (XHR, since Eden can't report progress — isolated, documented exception in lib/upload.ts) → Stage-2 editor for rating/source on the created post. URL import shown but disabled (future plugin); tags deferred. - Detail page: inline Edit for rating/source via PATCH (useUpdateAsset). - Shared RatingControl; date-crash fix; gallery hover card; sticky footer; theme switcher in the top bar; empty-state SVG; placeholder tags dropped; global pointer cursor. Dev / storage: - Uploaded assets now live under host-visible ./data/storage (STORAGE_ROOT default). - `bun run dev` runs the API from the repo root so root .env + STORAGE_ROOT resolve. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (6)
📝 WalkthroughWalkthroughAdds unrated rating support, asset update plumbing, a typed core events bus, a PATCH asset endpoint, immediate upload and metadata editing, and several UI/layout updates. ChangesAsset metadata, upload, events, and UI
Sequence DiagramssequenceDiagram
participant User
participant UploadPage
participant uploadAsset
participant API
participant MetadataEditor
participant useUpdateAsset
User->>UploadPage: selects or drops file
UploadPage->>uploadAsset: uploadAsset(file, options)
uploadAsset->>API: POST /api/v1/assets
API-->>uploadAsset: AssetDto or deduped response
uploadAsset-->>UploadPage: {asset, deduped}
UploadPage->>MetadataEditor: render uploaded asset
User->>MetadataEditor: edits rating/source
MetadataEditor->>useUpdateAsset: mutate patch
useUpdateAsset->>API: PATCH /api/v1/assets/:id
API-->>useUpdateAsset: updated AssetDto
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 9
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/web/src/routes/__root.tsx`:
- Around line 87-104: The landing page currently loses access to the theme
control because ThemeSwitcher is only rendered inside the non-home header branch
in __root.tsx. Update the layout so ThemeSwitcher is available on the home route
too, either by moving it outside the !isHome gate in the root header or by
rendering it in the home route component, while keeping AccountLinks and the
existing header structure intact.
In `@apps/web/src/routes/post-detail.tsx`:
- Around line 190-196: Disable the source input while update is pending so it
cannot be edited during an in-flight save; update the input in post-detail.tsx
alongside the existing update.isPending locks used for the rating control and
buttons. Use the same pending state that drives the Save flow so the source
value cannot diverge from the PATCH payload and then get overwritten by the
refetch sync.
- Around line 146-150: The edit form’s mutation error state is not being cleared
when leaving or re-entering edit mode, so `update.isError` can persist and show
a stale banner. Update the `cancel()` handler and the logic that opens the
editor in `post-detail.tsx` to call `update.reset()` so the mutation state is
cleared whenever the user exits or reopens editing. Use the existing `update`
mutation and `setEditing` flow in the component to place the reset in the right
spots.
In `@apps/web/src/routes/posts.tsx`:
- Around line 129-134: The gallery hover card uses HoverPopover with default
interactive dialog behavior even though PostHoverCard is read-only. Update the
HoverPopover usage in the post gallery mapping to pass interactive={false} so it
behaves like a tooltip and avoids the sticky hover corridor; keep the change
localized to the HoverPopover/PostHoverCard render path.
In `@apps/web/src/routes/upload.tsx`:
- Around line 127-140: The upload picker is not keyboard-accessible because the
hidden file input in the upload form cannot receive focus and the clickable
label container is not focusable. Update the upload control around the
label/onDrop area and the onInputChange file input so keyboard users can trigger
file selection, e.g. make the visible trigger focusable and operable from the
keyboard while keeping the file input reachable through the control rather than
fully hidden from assistive input.
- Around line 188-198: The rating update in changeRating is being stored
optimistically in local state without waiting for the PATCH to succeed, which
can leave the UI showing an unsaved value and block retries. Update the Upload
route component so the rating is only committed after a successful mutation, or
revert it on failure; use the existing changeRating handler, the rating state,
and update.mutate to wire success/error handling and avoid relying on the stale
local rating for retry logic.
In `@packages/core/test/asset-service.test.ts`:
- Around line 69-74: The fake repository update path in the asset-service test
currently resets updatedAt to the epoch instead of matching production behavior.
Update the update implementation in the test fixture so that when the update
method runs it advances updatedAt to a fresh current timestamp, while keeping
the existing row patching logic intact. Use the update method and its
Object.assign-based row mutation in the test setup as the place to align the
fake with the real repository.
In `@packages/db/src/schema.ts`:
- Line 80: The new DB default for rating was changed to "unrated", but the core
service test fake in fakeRepo.create() still falls back to "questionable", so
update that test double to match the production default. Adjust the
asset-service test helper in asset-service.test.ts so the synthesized rating
uses "unrated" when input.rating is missing, keeping the upload-path behavior
aligned with the schema and preventing regressions from being masked.
In `@packages/events/src/typed-event-emitter.ts`:
- Around line 72-74: The direct calls to onListenerError inside
TypedEventEmitter’s emit flow can let a failing error hook escape and break the
fire-and-forget contract. Update the emit listener-error handling so both the
Promise.catch path and the synchronous catch path protect the onListenerError
callback itself with their own error suppression/try-catch, ensuring emit()
never throws or produces an unhandled rejection because the hook failed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e42067d9-f0ff-451d-b2b0-0844cfadf428
📒 Files selected for processing (33)
.gitignoreapps/api/src/env-config.tsapps/api/src/server.tsapps/api/test/server.test.tsapps/web/src/components/popover/post-hover-card.tsxapps/web/src/components/rating-control.tsxapps/web/src/lib/assets.tsapps/web/src/lib/upload.tsapps/web/src/routes/__root.tsxapps/web/src/routes/post-detail.tsxapps/web/src/routes/posts.tsxapps/web/src/routes/upload.tsxapps/web/src/styles.csspackage.jsonpackages/core/src/core.tspackages/core/src/events/index.tspackages/core/src/index.tspackages/core/src/search/asset-query.tspackages/core/src/services/asset-service.tspackages/core/test/asset-service.test.tspackages/db/drizzle/0001_bored_harpoon.sqlpackages/db/drizzle/0002_needy_red_ghost.sqlpackages/db/drizzle/meta/0001_snapshot.jsonpackages/db/drizzle/meta/0002_snapshot.jsonpackages/db/drizzle/meta/_journal.jsonpackages/db/src/index.tspackages/db/src/repositories/asset-repository.tspackages/db/src/schema.tspackages/db/test/asset-repository.test.tspackages/events/src/index.tspackages/events/src/typed-event-emitter.tspackages/events/test/typed-event-emitter.test.tsscripts/seed.ts
- web/home: render ThemeSwitcher on the landing page (lost when it moved to the
non-home header).
- web/post-detail: reset mutation state on cancel/open (no stale error banner);
disable the source input while a save is pending.
- web/posts: gallery hover card is read-only → HoverPopover interactive={false}.
- web/upload: keyboard-accessible picker (sr-only file input + focus-within ring);
rating edits are optimistic but revert on failed PATCH and retry correctly
(track savedRating).
- events: guard onListenerError so a throwing error-hook can't break emit()'s
fire-and-forget contract (+ test).
- core test: fake repo now defaults rating to "unrated" and bumps updatedAt on
update, matching the real schema/repository.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@coderabbitai review |
✅ Action performedReview finished.
|
Reworks the upload flow to match Danbooru and adds the supporting backend: an
unrateddefault rating, post-metadata editing, and a Core event bus so future plugins (auto-tagging, similar-finder, thumbnails, OCR) can react to uploads. Includes assorted web-layout polish. (One combined PR per request; the resumable transport remains a deliberate follow-up.)Core / data
unratedrating, now the default (a fresh upload is unrated until classified). Two-step migration (ALTER TYPE … ADD VALUE, thenSET DEFAULT) so the new value commits before it's used; verified on a fresh DB.AssetRepository.update+AssetService.update(mutable fields:rating,source). Search compiler acceptsrating:unrated.@bunbooru/events: a generic, dependency-freeTypedEventEmitter(fire-and-forget, error-isolated). Core definesasset.createdand emits it on a new upload (not on dedupe) — the hook for future plugins (CLAUDE.md Event Rule). Unit-tested.API
POST /api/v1/assetsacceptssource; rating union includesunrated.PATCH /api/v1/assets/:id(rating, source); shared rating/id/source schemas. Tests for forward/404/unrated/invalid.Web
fetchcan't report upload progress) — a deliberate, documented exception isolated toapps/web/src/lib/upload.ts; all metadata calls stay on Eden. Aborts in-flight on reset/unmount.PATCH(useUpdateAsset).RatingControl; detail-page date-crash fix; gallery hover card; sticky footer; theme switcher in the top bar; empty-state SVG; placeholder tags dropped; global pointer cursor.Dev / storage
./data/storage(STORAGE_ROOTdefault)../datais root-owned by the Docker mounts, so a one-timesudo install -d -o "$USER" -g "$USER" data/storageis needed (documented inenv-config).bun run devruns the API from the repo root so root.env+STORAGE_ROOTresolve.Validation
bun run typecheck·bun run test(126 pass) ·bun run lint:boundaries— all green./filesmoke-tested through the dev proxy.🤖 Generated with Claude Code
Summary by CodeRabbit