Skip to content

feat: Danbooru-style uploader, unrated rating, post metadata editing + upload event - #12

Merged
deckyfx merged 2 commits into
mainfrom
feat/upload-flow
Jun 29, 2026
Merged

deckyfx merged 2 commits into
mainfrom
feat/upload-flow

Conversation

@deckyfx

@deckyfx deckyfx commented Jun 29, 2026 •

Copy link
Copy Markdown
Owner

Reworks the upload flow to match Danbooru and adds the supporting backend: an unrated default 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

  • unrated rating, now the default (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 fields: 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 (not on dedupe) — the hook for future plugins (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 forward/404/unrated/invalid.

Web

  • Two-stage uploader: pick/drop a file → it uploads immediately with a progress bar, then a Stage-2 editor sets rating/source on the created post. URL-import field shown but disabled (future plugin); tags deferred.
    • Progress requires XMLHttpRequest (Eden/fetch can't report upload progress) — a deliberate, documented exception isolated to apps/web/src/lib/upload.ts; all metadata calls stay on Eden. Aborts in-flight on reset/unmount.
  • Detail page: inline Edit for rating/source via PATCH (useUpdateAsset).
  • Shared 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

  • Uploaded assets now live under host-visible ./data/storage (STORAGE_ROOT default). ./data is root-owned by the Docker mounts, so a one-time sudo install -d -o "$USER" -g "$USER" data/storage is needed (documented in env-config).
  • bun run dev runs the API from the repo root so root .env + STORAGE_ROOT resolve.

Validation

  • bun run typecheck · bun run test (126 pass) · bun run lint:boundaries — all green.
  • Migration verified on a throwaway DB. Upload→default-unrated→PATCH→/file smoke-tested through the dev proxy.
  • Pre-push CodeRabbit CLI review: 8 findings (3 major) applied (emit moved out of dedupe-race try; abort in-flight upload; reset edit-state across asset identity; etc.).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added an unrated rating option across the app.
    • Added in-place editing for asset rating and source from post details.
    • Replaced the upload flow with an immediate progress-enabled experience (preview, deduplication, abort support) and post-upload metadata editing.
    • Added hover cards for posts with quick asset details.
  • UI/UX Improvements
    • Updated layout to keep the footer at the bottom, refreshed header/footer content, and improved empty/“no tags” states.
  • Bug Fixes
    • Improved robustness of date rendering and ensured updated asset metadata refreshes promptly in the UI.

…+ 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>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d2cdd8f6-82a9-4dbf-9d7e-8aa0f4a1e930

📥 Commits

Reviewing files that changed from the base of the PR and between 7810679 and b127caf.

📒 Files selected for processing (7)
  • apps/web/src/routes/home.tsx
  • apps/web/src/routes/post-detail.tsx
  • apps/web/src/routes/posts.tsx
  • apps/web/src/routes/upload.tsx
  • packages/core/test/asset-service.test.ts
  • packages/events/src/typed-event-emitter.ts
  • packages/events/test/typed-event-emitter.test.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/web/src/routes/home.tsx
🚧 Files skipped from review as they are similar to previous changes (6)
  • apps/web/src/routes/posts.tsx
  • packages/core/test/asset-service.test.ts
  • packages/events/test/typed-event-emitter.test.ts
  • apps/web/src/routes/post-detail.tsx
  • packages/events/src/typed-event-emitter.ts
  • apps/web/src/routes/upload.tsx

📝 Walkthrough

Walkthrough

Adds 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.

Changes

Asset metadata, upload, events, and UI

Layer / File(s) Summary
Typed event emitter
packages/events/src/typed-event-emitter.ts, packages/events/src/index.ts, packages/events/test/typed-event-emitter.test.ts
Defines the typed emitter API and runtime, re-exports it from the package entrypoint, and adds tests for subscription, unsubscribe, once, and listener error handling.
Unrated rating support
packages/db/src/schema.ts, packages/db/drizzle/0001_bored_harpoon.sql, packages/db/drizzle/0002_needy_red_ghost.sql, packages/db/drizzle/meta/*, packages/core/src/search/asset-query.ts, packages/db/test/asset-repository.test.ts
Extends the rating enum and default to include "unrated", updates the related migration snapshots and journal, adjusts search validation, and updates the schema test assertion.
Asset update plumbing and core events
packages/db/src/repositories/asset-repository.ts, packages/db/src/index.ts, packages/core/src/events/index.ts, packages/core/src/core.ts, packages/core/src/services/asset-service.ts, packages/core/src/index.ts, packages/core/test/asset-service.test.ts
Adds AssetUpdate, repository update support, CoreEvents, event bus wiring in Core, AssetService.update, and asset creation event emission, with matching core tests.
API asset routes
apps/api/src/server.ts, apps/api/test/server.test.ts
Adds shared request schemas, forwards source on asset creation, introduces PATCH /api/v1/assets/:id, validates :id with the shared schema, and extends the API tests for patch behavior.
Upload helper and immediate upload page
apps/web/src/lib/upload.ts, apps/web/src/lib/assets.ts, apps/web/src/routes/upload.tsx
Adds the XHR upload helper and asset mutation hook, then rewrites the upload page to start uploads immediately, show progress, and edit rating/source after upload.
Browse and post detail UI
apps/web/src/components/rating-control.tsx, apps/web/src/components/popover/post-hover-card.tsx, apps/web/src/routes/posts.tsx, apps/web/src/routes/post-detail.tsx
Adds the rating control and hover card components, updates the posts grid and empty state, and adds inline asset editing on the post detail page.
Shell, styling, and storage defaults
apps/web/src/routes/__root.tsx, apps/web/src/styles.css, apps/api/src/env-config.ts, scripts/seed.ts, .gitignore, package.json
Changes the root app shell layout and footer/header content, adds pointer cursors for interactive elements, updates storage-root defaults in API config and seed setup, adjusts .gitignore, and changes the dev script.

Sequence Diagrams

sequenceDiagram
  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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • deckyfx/bunbooru#6: Added the asset-service and API surfaces that this PR extends with update handling and creation events.
  • deckyfx/bunbooru#9: Touches the same asset route and storage-root code paths that this PR updates.
  • deckyfx/bunbooru#11: Modifies the same rating search logic that this PR extends to accept "unrated".

Poem

🐰 Hop, hop—new tools in the den,
unrated eggs and assets again.
XHR pings, then the hops begin,
events go twinkle, updates roll in.
I nibble a carrot and grin right wide—
this gallery grew with a bunny’s stride.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.16% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main changes: immediate uploader flow, unrated rating, metadata editing, and the new upload event bus.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/upload-flow

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c10755 and 7810679.

📒 Files selected for processing (33)
  • .gitignore
  • apps/api/src/env-config.ts
  • apps/api/src/server.ts
  • apps/api/test/server.test.ts
  • apps/web/src/components/popover/post-hover-card.tsx
  • apps/web/src/components/rating-control.tsx
  • apps/web/src/lib/assets.ts
  • apps/web/src/lib/upload.ts
  • apps/web/src/routes/__root.tsx
  • apps/web/src/routes/post-detail.tsx
  • apps/web/src/routes/posts.tsx
  • apps/web/src/routes/upload.tsx
  • apps/web/src/styles.css
  • package.json
  • packages/core/src/core.ts
  • packages/core/src/events/index.ts
  • packages/core/src/index.ts
  • packages/core/src/search/asset-query.ts
  • packages/core/src/services/asset-service.ts
  • packages/core/test/asset-service.test.ts
  • packages/db/drizzle/0001_bored_harpoon.sql
  • packages/db/drizzle/0002_needy_red_ghost.sql
  • packages/db/drizzle/meta/0001_snapshot.json
  • packages/db/drizzle/meta/0002_snapshot.json
  • packages/db/drizzle/meta/_journal.json
  • packages/db/src/index.ts
  • packages/db/src/repositories/asset-repository.ts
  • packages/db/src/schema.ts
  • packages/db/test/asset-repository.test.ts
  • packages/events/src/index.ts
  • packages/events/src/typed-event-emitter.ts
  • packages/events/test/typed-event-emitter.test.ts
  • scripts/seed.ts

Comment thread apps/web/src/routes/__root.tsx Resolved
Comment thread apps/web/src/routes/post-detail.tsx Resolved
Comment thread apps/web/src/routes/post-detail.tsx Resolved
Comment thread apps/web/src/routes/posts.tsx Resolved
Comment thread apps/web/src/routes/upload.tsx Resolved
Comment thread apps/web/src/routes/upload.tsx Resolved
Comment thread packages/db/src/schema.ts Resolved
- 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>
@deckyfx

deckyfx commented Jun 29, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant