Compare commits

...

113 Commits

Author SHA1 Message Date
b842106e44 fix: match pagination button size to admin filter buttons (default size)
All checks were successful
Build and Push Frontend Image / build (push) Successful in 1m11s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 12:07:44 +01:00
9abcd715d7 feat: add subtitles to /play/buttplug and /play/recordings page headers
All checks were successful
Build and Push Frontend Image / build (push) Successful in 1m12s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 12:04:24 +01:00
ab0af9a773 feat: extract Pagination component and use it on all paginated pages
All checks were successful
Build and Push Frontend Image / build (push) Successful in 1m13s
- New lib/components/pagination/pagination.svelte with numbered pages,
  ellipsis for large ranges, and prev/next buttons
- All 6 admin pages (users, articles, videos, recordings, comments,
  queues) now show enumerated page numbers next to the "Showing X–Y of Z"
  label; offset is derived from page number * limit
- Public pages (videos, models, magazine) replace their inline
  totalPages/pageNumbers derived state with the shared component
- Removes ~80 lines of duplicated pagination logic across 9 files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 12:01:13 +01:00
fbd2efa994 feat: server-side pagination and filtering for admin queues page
- Move queue, status, and offset to URL search params (?queue=&status=&offset=)
- Load jobs server-side in +page.server.ts with auth token (matches other admin pages)
- Derive total from adminQueues counts (waiting+active+completed+failed+delayed)
  so pagination knows total without an extra query
- Add fetchFn/token params to getAdminQueueJobs for server-side use
- Retry/remove/pause/resume actions now use invalidateAll() instead of local state

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 11:49:50 +01:00
79932157bf fix: revoke points when a comment is deleted
All checks were successful
Build and Push Backend Image / build (push) Successful in 43s
- revokePoints now accepts optional recordingId; when absent it deletes
  one matching row (for actions like COMMENT_CREATE that have no recording)
- deleteComment queues revokePoints + checkAchievements so leaderboard
  and social achievements stay in sync

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 11:16:18 +01:00
04b0ec1a71 fix: revoke gamification points on recording delete + fix comment collection
- deleteRecording now queues revokePoints for RECORDING_CREATE (and
  RECORDING_FEATURED if applicable) before deleting a published recording,
  so leaderboard points are correctly removed
- Fix comment stat/achievement queries using collection "recordings" instead
  of "videos" — comments are stored under collection "videos", so the count
  was always 0, breaking COMMENT_CREATE stats and social achievements

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 11:13:01 +01:00
cc693d8be7 fix: prevent achievement points from being re-awarded on republish
All checks were successful
Build and Push Backend Image / build (push) Successful in 1m2s
Once an achievement is unlocked, preserve date_unlocked permanently
instead of clearing it to null when the user drops below the threshold
(e.g. on unpublish). This prevents the wasUnlocked check from returning
false on republish, which was causing achievement points to be re-awarded
on every publish/unpublish cycle.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 20:04:20 +01:00
52aa00dd13 fix: embed DECAY_LAMBDA as SQL literal to avoid pg type inference failure
All checks were successful
Build and Push Backend Image / build (push) Successful in 45s
Build and Push Frontend Image / build (push) Successful in 1m12s
PostgreSQL cannot resolve the type of a parameterized $1 = 0.005 in
-$1 * EXTRACT(EPOCH ...) and fails with an operator type error. Using
sql.raw() embeds the constant directly in the query string so userId
is the only parameter.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 19:55:45 +01:00
8085b40af8 fix: use NOW() in weighted score query instead of JS Date parameter
Passing a JS Date to a Drizzle sql template serializes it as a locale
string (e.g. "Mon Mar 09 2026 19:51:22 GMT+0100") which PostgreSQL
cannot parse as timestamptz, causing the gamification worker to fail.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 19:52:03 +01:00
5f40a812d3 feat: gamification queue with deduplication and unpublish revoke
- Add migration 0004: partial unique index on user_points (user_id, action, recording_id)
  for RECORDING_CREATE and RECORDING_FEATURED to prevent earn-on-republish farming
- Add revokePoints() to gamification lib; awardPoints() now uses onConflictDoNothing
- Add gamificationQueue (BullMQ) with 3-attempt exponential backoff
- Add gamification worker handling awardPoints, revokePoints, checkAchievements jobs
- Move all inline gamification calls in recordings + comments resolvers to queue
- Revoke RECORDING_CREATE points when a recording is unpublished (published → draft)
- Register gamification worker at server startup alongside mail worker

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 19:50:33 +01:00
1b724e86c9 chore: lint and format
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 19:38:37 +01:00
a9e4ed6049 feat: refactor play area into sidebar layout with buttplug, recordings, and leaderboard sub-pages
- Add /play sidebar layout (mobile nav + desktop sidebar) with SexyBackground
- Move buttplug device control to /play/buttplug with Empty component and scan button
- Move recordings from /me/recordings to /play/recordings
- Move leaderboard to /play/leaderboard; redirect /leaderboard → /play/leaderboard
- Redirect /me/recordings → /play/recordings and /play → /play/buttplug
- Remove recordings entry from /me sidebar nav
- Rename "SexyPlay" → "Play", swap bluetooth icon for rocket, remove subtitle
- Add play.nav i18n keys (play, recordings, leaderboard, back_to_site, back_mobile)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 19:33:28 +01:00
66179d7ba8 style: streamline draft/published badge across recording card and admin table
- Replace custom inline span+getStatusColor with Badge component in recording card
- Align admin recordings table badge to same style (outline, green/yellow)
- Use i18n label in admin table instead of raw status string
- Remove unused cn import and getStatusColor helper

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 18:43:18 +01:00
3a8fa7d8ce style: refine admin edit forms and fix mobile padding
- Remove back button from admin entity edit pages (sidebar handles navigation)
- Remove cancel button from video/article forms, make submit button full-width
- Show actual entity title + subtitle on video/article edit pages
- Remove asterisks from Title/Slug field labels in i18n
- Remove px-3 sm:px-0 from all admin list page headers/filters (fixes mobile padding)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 18:38:38 +01:00
fddc3f15d0 feat: fix recording save and add publish/unpublish support
- Fix broken fetch("/api/sexy/recordings") → use createRecording GraphQL service
- Round duration to integer before sending (GraphQL Int type)
- Add updateRecording mutation to services
- Add publish/unpublish buttons to RecordingCard (draft ↔ published)
- Remove "Go to Play" button from recordings page header
- Add publish/unpublish i18n keys

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 18:26:42 +01:00
d9a60f0572 style: refine admin & me UI — card forms, back arrows, avatar in admin sidebar, Empty component
- Replace ← text with icon-[ri--arrow-left-line] in admin and me layouts
- Add avatar + admin shield badge to admin sidebar header
- Wrap all admin edit forms in Card (bg-card/50 border-primary/20) with styled inputs
- Fix sm:pl-6 → lg:pl-6 so extra left padding only applies when sidebar is visible
- Update security form submit button to gradient style matching profile
- Remove "View Public Profile" button from me/profile
- Use shadcn-svelte Empty component for recordings empty state
- Install empty component via shadcn-svelte

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 18:16:39 +01:00
ba648c796a feat: refactor /me into admin-style layout with profile, security, recordings, analytics sub-pages
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 17:47:00 +01:00
27e2ff5f66 feat: add Meta title tags to all admin pages
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 17:23:35 +01:00
b7a29c55b3 style: fix header nav gap
All checks were successful
Build and Push Frontend Image / build (push) Successful in 1m16s
2026-03-09 10:24:14 +01:00
99b2ed7f2b feat: show login/signup buttons on mobile header
All checks were successful
Build and Push Frontend Image / build (push) Successful in 1m24s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 10:00:02 +01:00
8357aecf98 feat: add ring border to logo icon matching avatar style
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 09:58:27 +01:00
ab3d9f4118 feat: show auth icon strip on mobile header, move burger outside pill
All checks were successful
Build and Push Frontend Image / build (push) Successful in 1m16s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 09:50:25 +01:00
5219fae36a feat: add structured logging to BullMQ queues and workers
All checks were successful
Build and Push Backend Image / build (push) Successful in 43s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 09:33:43 +01:00
7de1bf7a03 style: fix header
All checks were successful
Build and Push Frontend Image / build (push) Successful in 1m46s
2026-03-09 08:56:49 +01:00
a4fd1ff18b fix: soften header shadow glow
All checks were successful
Build and Push Frontend Image / build (push) Successful in 1m15s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 20:32:17 +01:00
6605980a43 style: move page gradient to global background so it shows behind header
All checks were successful
Build and Push Frontend Image / build (push) Successful in 1m19s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:32:58 +01:00
15d9708072 Revert "feat: fixed header with hero section extending behind it"
This reverts commit fc97c1b84b.
2026-03-08 19:25:15 +01:00
89c4c390fa Revert "feat: extend page-hero behind fixed header on all pages"
This reverts commit f5ff59b910.
2026-03-08 19:25:15 +01:00
f5ff59b910 feat: extend page-hero behind fixed header on all pages
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:24:22 +01:00
fc97c1b84b feat: fixed header with hero section extending behind it
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:22:41 +01:00
e2abb0794a style: use text-foreground color for burger menu lines
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:18:39 +01:00
2644e033b4 style: remove underline from logout button hover
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:16:43 +01:00
ee1cea6d01 style: match logout button hover to other icon buttons, destructive color on hover
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:16:04 +01:00
1496399b96 style: remove header border, keep glow shadow only
All checks were successful
Build and Push Frontend Image / build (push) Successful in 1m15s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:09:55 +01:00
075f64f4e3 style: single crisp primary border with soft glow on header
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:06:43 +01:00
8c6c98d612 style: edgy glowing bottom border on header
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:05:41 +01:00
28be084781 style: transparent header, no scroll tracking
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:04:25 +01:00
21b8d2c223 feat: transparent header at top, solid on scroll
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:03:39 +01:00
b315062d43 revert: restore original header styling
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:02:42 +01:00
5bef996dbc fix: use derived override pattern for selectedQueue to avoid captured state warning
All checks were successful
Build and Push Backend Image / build (push) Successful in 43s
Build and Push Frontend Image / build (push) Successful in 1m38s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 18:36:50 +01:00
da2484d232 fix: replace nested button with div[role=button] on queue cards
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 18:35:16 +01:00
722392d19e chore: lint and format
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 18:32:39 +01:00
a07a5cb091 fix: suppress false-positive svelte state warning on queues page
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 18:31:35 +01:00
ea23233645 feat: add BullMQ job queue with admin monitoring UI
All checks were successful
Build and Push Backend Image / build (push) Successful in 48s
Build and Push Buttplug Image / build (push) Successful in 3m26s
Build and Push Frontend Image / build (push) Successful in 1m11s
- Add BullMQ to backend; mail jobs (verification, password reset) now enqueued instead of sent inline
- Mail worker processes jobs with 3-attempt exponential backoff retry
- Admin GraphQL resolvers: adminQueues, adminQueueJobs, adminRetryJob, adminRemoveJob, adminPauseQueue, adminResumeQueue
- Admin frontend page at /admin/queues: queue cards with counts, job table with status filter, retry/remove/pause actions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 18:25:09 +01:00
6dcdc0130b chore: streamline package.json files 2026-03-08 17:46:04 +01:00
8508e1f6e9 style: reduce header background opacity for softer appearance
All checks were successful
Build and Push Frontend Image / build (push) Successful in 1m13s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 17:39:47 +01:00
6abcfc7363 chore: remove unused super-sitemap dependency
All checks were successful
Build and Push Buttplug Image / build (push) Successful in 3m38s
Build and Push Frontend Image / build (push) Successful in 1m12s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 17:22:55 +01:00
d4b3968518 fix: suppress Rust compiler warnings in buttplug
- #[allow(dead_code)] on FFICallbackContextWrapper, Connected variant,
  Unsubscribe variant, and device_event_receiver field
- let _ = for unused Result from callback.call1() (x2) and .send().await

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 17:21:58 +01:00
8f4999f127 chore: upgrade pnpm from 10.19.0 to 10.31.0
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 17:19:39 +01:00
4b53a25fa3 fix: proper build script calls in package.json 2026-03-08 17:16:46 +01:00
4f85637875 fix: upgrade Node.js to 22.14.0, add svelte-kit sync before build
All checks were successful
Build and Push Backend Image / build (push) Successful in 1m9s
Build and Push Buttplug Image / build (push) Successful in 4m21s
Build and Push Frontend Image / build (push) Successful in 1m15s
- Node 22.11.0 is below Vite's minimum requirement of 22.12+
- svelte-kit sync must run before vite build to generate
  .svelte-kit/tsconfig.json which tsconfig.json extends

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 17:14:51 +01:00
1175b4d0e6 chore: update @internationalized/date to 3.12.0
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 17:12:57 +01:00
2afa3c6e9b fix: replace raw HTML buttons with Button component in admin, remove vite-plugin-wasm
- Use Button component for photo remove, editor tab toggle, and model
  pill buttons across admin/users, admin/articles, admin/videos
- Remove vite-plugin-wasm from frontend devDependencies (no longer
  needed since WASM is served by the buttplug nginx container)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 17:11:24 +01:00
b55cebea4e ci: add path filters to all workflow triggers
Each image only builds when its relevant source changes:
- backend: packages/backend/**, packages/types/**, Dockerfile.backend
- frontend: packages/frontend/**, packages/types/**, Dockerfile
- buttplug: packages/buttplug/**, Dockerfile.buttplug, nginx.buttplug.conf

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 16:49:48 +01:00
9845553d49 fix: switch buttplug WASM to --target web for browser compatibility
All checks were successful
Build and Push Backend Image / build (push) Successful in 16s
Build and Push Buttplug Image / build (push) Successful in 3m37s
Build and Push Frontend Image / build (push) Successful in 1m15s
--target bundler generates static WASM ESM imports that only work
through a bundler. --target web generates fetch-based WASM loading
via import.meta.url which browsers handle natively.

- Change wasm-pack build target from bundler to web
- Call wasmModule.default() (init) after import in maybeLoadWasm
- Add .gitignore to exclude dist/ and wasm/ build outputs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 14:12:01 +01:00
ced0a08da3 fix: serve buttplug locally in dev instead of Docker
Add a minimal Node.js static server (serve.mjs) to the buttplug package
that serves dist/ and wasm/ on port 8080 with correct MIME types.
Update dev:buttplug to use it instead of docker compose, avoiding a
full Rust/WASM Docker build on every dev start.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 13:55:31 +01:00
f880aa5957 feat: externalize buttplug as separate nginx container
- Add Dockerfile.buttplug: builds Rust/WASM + TS, serves via nginx
- Add nginx.buttplug.conf: serves /dist and /wasm with correct MIME types
- Add .gitea/workflows/docker-build-buttplug.yml: path-filtered CI workflow
- Strip Rust toolchain and buttplug build from frontend Dockerfile
- Move buttplug to devDependencies (types only at build time)
- Remove vite-plugin-wasm from frontend (WASM now served by nginx)
- Add /buttplug proxy in vite.config (dev: localhost:8080)
- Add buttplug service to compose.yml
- Load buttplug dynamically in play page via runtime import
- Fix faq page: suppress no-unnecessary-state-wrap for reassigned SvelteSet

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 13:49:38 +01:00
239128bf5e fix: buttplug lint errors
All checks were successful
Build and Push Backend Image / build (push) Successful in 17s
Build and Push Frontend Image / build (push) Successful in 4m34s
2026-03-08 13:28:59 +01:00
0a50c3efd8 fix: remove sitemap.xml
All checks were successful
Build and Push Backend Image / build (push) Successful in 16s
Build and Push Frontend Image / build (push) Successful in 4m29s
2026-03-08 12:04:50 +01:00
af4a11b73c style: apply prettier formatting to svelte and ts files
Some checks failed
Build and Push Backend Image / build (push) Successful in 1m3s
Build and Push Frontend Image / build (push) Has been cancelled
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 11:49:43 +01:00
627ce75719 fix: restore \$state on SvelteMap in device-mapping-dialog
The variable is fully reassigned in an \$effect, so \$state is required
for reactivity. Suppress the no-unnecessary-state-wrap lint rule with a
comment explaining the reason.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 11:47:21 +01:00
446e9f835b fix: use writable \$derived for search inputs, remove unnecessary \$state wrap
- Replace \$state + \$effect pattern with writable \$derived (Svelte 5.25+)
  for all searchValue instances across list pages — cleaner and lint-compliant
- Remove now-unused untrack imports from those files
- Drop \$state() wrapper around SvelteMap in device-mapping-dialog
  (SvelteMap is already reactive)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 11:46:15 +01:00
422f97417e fix: resolve vite-plugin-svelte warnings
- image-viewer: replace backdrop div with button for a11y
- file-drop-zone: wrap prop check in \$effect to avoid state_referenced_locally
- about: use \$derived for stats array
- magazine: use \$derived for featuredArticle
- play: add role/keyboard support to seek bar slider; fix \$state on SvelteMap in device-mapping-dialog
- admin/videos/[id]: add <track kind="captions"> to video element

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 11:41:58 +01:00
edee98b552 fix: use untrack() in \$state initialisers to silence state_referenced_locally warnings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 11:31:51 +01:00
b9b98f178f fix: sync reactive state with data prop using \$effect
Replaces bare \$state(data.x) initialisers (which only capture the
initial value) with \$state + \$effect pairs so that state stays in sync
whenever page data is invalidated or the URL changes. Affects all list
pages (searchValue) and all edit/detail pages (form fields).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 11:06:30 +01:00
dc1850126b fix: run DB migrations automatically at backend startup
Instead of relying on a manual `pnpm db:migrate` step (which was
connecting to a different postgres than the Docker container), the
backend now calls drizzle migrate() before the server starts. This
ensures migrations always run against the correct database on startup.

Also fixes the Dockerfile to copy migrations into dist/migrations so
the path resolves correctly in the compiled output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 11:00:36 +01:00
4d81266cb1 feat: add dedicated model photo separate from avatar
Adds a `photo` field to the users table (and a migration) that serves
as a dedicated profile/card image for models. This is now used in model
cards and on the model single page, while `avatar` is reserved for
comments, article authors, and the user profile page.

- DB: `photo` column on `users` with FK to `files`
- GraphQL: exposed on ModelType, UserType, AdminUserDetailType; photoId arg on adminUpdateUser
- Services: photo field in MODELS_QUERY, MODEL_BY_SLUG_QUERY, ADMIN_GET/UPDATE_USER
- Frontend: model cards and single page use `photo ?? avatar` fallback
- Admin: model photo upload section in user edit page

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 10:54:27 +01:00
2980c0b637 fix: remove brand name text from mobile flyout header
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 10:42:22 +01:00
7af9c0d7ca fix: fix admin mobile nav overflow breaking layout on small screens
Mobile nav now scrolls horizontally with hidden scrollbar; nav items
don't shrink and show icon-only on xs, icon+label on sm and up.
Added scrollbar-none utility to app.css.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 10:39:12 +01:00
76d71ee7c3 fix: remove comments list timestamp gap
All checks were successful
Build and Push Backend Image / build (push) Successful in 17s
Build and Push Frontend Image / build (push) Successful in 4m25s
2026-03-07 19:37:52 +01:00
90497e9e7c fix: resolve TypeScript build errors from leftJoin nullable types
Some checks failed
Build and Push Backend Image / build (push) Successful in 42s
Build and Push Frontend Image / build (push) Has been cancelled
Non-null assert photo/achievement ids that are structurally non-null
due to FK constraints but nullable in Drizzle's leftJoin return type.
Add missing description field to enrichVideo model select and map.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 19:33:16 +01:00
a558449964 chore: remove eslint warn rule
Some checks failed
Build and Push Backend Image / build (push) Failing after 29s
Build and Push Frontend Image / build (push) Successful in 4m12s
2026-03-07 19:28:17 +01:00
e236ced12a refactor: replace all explicit any types with proper TypeScript types
Backend resolvers: typed enrichArticle/enrichVideo/enrichModel with DB
and $inferSelect types, SQL<unknown>[] for conditions arrays, proper
enum casts for status/role fields, $inferInsert for .set() updates,
typed raw SQL result rows in gamification, ReplyLike interface for
ctx.reply in auth. Frontend: typed catch blocks with Error/interface
casts, isActiveLink param, adminGetUser response, tags filter callback.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 19:25:04 +01:00
8313664d70 chore: fix all lint errors and format codebase
- Remove unused `or` import in comments resolver
- Remove unused `users` import in recordings resolver
- Add index keys to pagination {#each} loops in videos, models, magazine
- Remove stale svelte-ignore comment in header (a11y warnings no longer fired)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 19:06:57 +01:00
ae0929ad06 fix: replace arrow symbol with icon css in author profile link
All checks were successful
Build and Push Backend Image / build (push) Successful in 43s
Build and Push Frontend Image / build (push) Successful in 4m12s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 19:03:41 +01:00
b78831231d fix: select description from users in article enrichArticle query
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 19:02:53 +01:00
f90b045ca5 fix: add description to VideoModel type and GraphQL schema
Requesting description on the article author caused a GraphQL error
which the page.server.ts caught as a 404.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 19:01:52 +01:00
d2cbb1004f fix: show author description on magazine article page
Add description field to ARTICLE_BY_SLUG_QUERY and render it in the
author bio card below the name.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:58:42 +01:00
77ebccf6fa feat: redesign avatar upload as circular click-to-change UI
Replace generic file drop zone + tiny thumbnail with a 96px circular
avatar that shows a camera overlay on hover, upgrades preview to
thumbnail quality, and adds a compact remove button.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:55:56 +01:00
1c101406f6 fix: match admin background gradient to rest of the app
All checks were successful
Build and Push Backend Image / build (push) Successful in 44s
Build and Push Frontend Image / build (push) Successful in 4m4s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:51:40 +01:00
cb7720ca9c fix: smooth hero-to-content transition with transparent gradient fade
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:47:24 +01:00
df099b2700 fix: remove extra closing div in models pagination
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:42:39 +01:00
291f72381f feat: improve UX across all listing pages and homepage
- Make model/video cards fully clickable on homepage, models, videos, magazine, and tags pages
- Replace inline blob divs with SexyBackground component on magazine and play pages
- Replace magazine hero section with PageHero component for consistency
- Remove redundant action buttons from cards (cards are now the link targets)
- Fix nested anchor/button invalid HTML in magazine featured article
- Convert inner overlay anchors to aria-hidden divs to avoid nested <a> elements
- Add bg-muted skeleton placeholder to all card images
- Update magazine pagination to smart numbered style with ellipsis (matching videos/models)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:41:39 +01:00
1a2fab3e37 refactor: UX and styling improvements across frontend
- Fix login spinner (isLoading never set to true before await)
- Extract PageHero component, replace copy-pasted hero sections on videos/models/tags pages
- Replace inline plasma blobs with SexyBackground on videos/models/tags pages
- Make video/model/tag cards fully clickable (wrap in <a>), remove redundant Watch/View Profile buttons
- Convert inner overlay anchors to divs to avoid nested <a> elements
- Fix home page model avatar preset: mini → thumbnail (correct size for 96px display)
- Reduce home hero height: min-h-screen → min-h-[70vh]
- Remove dead hideName prop from Logo, simplify component
- Add brand name to mobile flyout panel header with gradient styling
- Remove dead _relatedVideos array, isBookmarked state, _handleBookmark from video detail page
- Clean up commented-out code blocks in video detail and models pages
- Note: tag card inner tag links converted to spans to avoid nested anchors

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:33:32 +01:00
56b57486dc fix: add upload/delete file endpoints and wire avatar update through profile
- Add POST /upload and DELETE /assets/:id routes to backend (session auth via session_token cookie)
- Add avatar arg to updateProfile GraphQL mutation and resolver
- Fix frontend to pass avatarId correctly on save, preserve existing avatar when unchanged
- Ignore 404 on file delete (already gone is fine)
- Remove broken folder lookup (getFolders is a stub, backend has no folder concept)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:22:22 +01:00
a050e886cb feat: replace slide-to-logout with avatar + name + logout button in header
Removes the drag-to-logout widget in favour of a clean inline layout:
- Desktop: avatar (links to /me), artist name, and a logout icon button
- Mobile flyout: user card with avatar, name, email, and logout button

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:12:18 +01:00
519fd45d8d feat: rebrand to Sexy, restyle logo with gradient icon and updated assets
- Rename brand from SexyArt to Sexy throughout i18n locale
- Apply primary→accent gradient to SVG icon stroke
- Remove brand name text from logo, icon-only display
- Switch logo font to Noto Sans bold (default), drop Dancing Script
- Update favicons, app icons, webmanifest, and add logo.svg

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:04:14 +01:00
0592d27a15 fix: redirect authenticated users away from login, signup, and password pages
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 15:58:12 +01:00
a38883e631 fix: align admin filter toggle buttons with search input height
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 15:51:13 +01:00
798495c3d6 fix: remove archived badge from recording card and i18n
All checks were successful
Build and Push Backend Image / build (push) Successful in 17s
Build and Push Frontend Image / build (push) Successful in 4m19s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 11:57:40 +01:00
fde0d63271 feat: remove archived status from recordings, deletions are now immediate
All checks were successful
Build and Push Backend Image / build (push) Successful in 45s
Build and Push Frontend Image / build (push) Successful in 4m3s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 11:42:13 +01:00
754a236e51 feat: add admin tables for comments and recordings
All checks were successful
Build and Push Backend Image / build (push) Successful in 44s
Build and Push Frontend Image / build (push) Successful in 4m20s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 11:29:48 +01:00
dfe49b5882 feat: allow users to delete their own comments on videos
All checks were successful
Build and Push Backend Image / build (push) Successful in 16s
Build and Push Frontend Image / build (push) Successful in 4m7s
Shows a delete button on each comment for the comment author and admins.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 11:19:50 +01:00
9ba848372a fix: make gamification calls non-blocking so errors don't fail core mutations
Some checks failed
Build and Push Backend Image / build (push) Successful in 43s
Build and Push Frontend Image / build (push) Has been cancelled
awardPoints/checkAchievements were awaited inline, so any gamification error
(DB constraint, missing table, etc.) would propagate as INTERNAL_SERVER_ERROR
on comment creation, recording plays, etc. Now they run fire-and-forget with
error logging, so the core action always succeeds.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 11:16:27 +01:00
dcf2fbd3d4 feat: enhance session security and freshness
All checks were successful
Build and Push Backend Image / build (push) Successful in 43s
Build and Push Frontend Image / build (push) Successful in 4m15s
- Sliding expiration: reset 24h TTL on every Redis session access
- SameSite=Strict on login and logout cookies (was Lax)
- Secure flag on logout cookie in production (was missing)
- Re-fetch user from DB on every request in buildContext so role/avatar/
  admin changes take effect immediately without requiring re-login

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 11:10:01 +01:00
bff354094e fix: add adminGetVideo/adminGetArticle queries to fix 404 on edit pages
Some checks failed
Build and Push Backend Image / build (push) Successful in 43s
Build and Push Frontend Image / build (push) Has been cancelled
The edit page loaders were calling adminListVideos/adminListArticles with the
old pre-pagination signatures and filtering by ID client-side, which broke
after pagination limited results to 50. Now fetches the single item by ID
directly via new adminGetVideo and adminGetArticle backend queries.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 11:05:21 +01:00
6f2f3b3529 fix: deduplicate model photos in public resolver to match admin behavior
All checks were successful
Build and Push Backend Image / build (push) Successful in 43s
Build and Push Frontend Image / build (push) Successful in 4m10s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 10:54:29 +01:00
f2871b98db style: apply prettier formatting across frontend components and pages
Some checks failed
Build and Push Backend Image / build (push) Successful in 1m4s
Build and Push Frontend Image / build (push) Has been cancelled
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 10:49:35 +01:00
9c5dba5c90 feat: add server-side pagination, search, and filtering to all collection and admin pages
- Public pages (videos, magazine, models): URL-driven search, sort, category/duration
  filters, and Prev/Next pagination (page size 24)
- Admin tables (videos, articles): search input, toggle filters, and pagination (page size 50)
- Tags page: tag filtering now done server-side via DB arrayContains query instead of
  fetching all items and filtering client-side
- Backend resolvers updated for videos, articles, models with paginated { items, total }
  responses and filter/sort/tag args

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 10:43:26 +01:00
c90c09da9a chore: cleanup
All checks were successful
Build and Push Backend Image / build (push) Successful in 49s
Build and Push Frontend Image / build (push) Successful in 4m18s
2026-03-06 19:25:07 +01:00
aed7b4a16f fix: restore admin role in User type, use image logo
- Add "admin" back to User.role union to fix backend TS build
- Replace SVG PeonyIcon with logo.png image in Logo component

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 18:04:49 +01:00
454c477c40 style: use rocket icon for all Go to Play buttons
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 17:42:49 +01:00
3cf81bd381 style: apply gradient to primary buttons in admin area
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 17:39:36 +01:00
ac63e59906 style: remove card wrapper from error page
Some checks failed
Build and Push Backend Image / build (push) Failing after 27s
Build and Push Frontend Image / build (push) Successful in 5m7s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 17:28:11 +01:00
19d29cbfc6 fix: replace flyout profile card with logout slider, i18n auth errors
- Replace static account card in mobile flyout with swipe-to-logout widget
- Remove redundant logout button from flyout bottom
- Make LogoutButton full-width via class prop and dynamic maxSlide
- Extract clean GraphQL error messages instead of raw JSON in all auth forms
- Add i18n keys for known backend errors (invalid credentials, email taken, invalid token)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 17:26:14 +01:00
0ec27117ae style: streamline /me page header to match admin dashboard style
Replace large gradient title with simple text-2xl font-bold heading,
matching the header pattern used across admin pages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 17:13:19 +01:00
ed9eb6ef22 style: fix admin table padding — edge-to-edge on mobile, no right pad on desktop
Mobile: remove horizontal padding so tables fill full width with top/bottom
borders only. Desktop: keep left padding, table extends to right edge.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 17:08:16 +01:00
609f116b5d feat: replace native date inputs with shadcn date picker
Add calendar + popover components and a custom DateTimePicker wrapper.
Video forms use date-only; article forms include a time picker.
Also add video player preview to the video edit form.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 17:03:35 +01:00
e943876e70 fix: prevent age verification dialog flicker on page load
Initialize isOpen as false and only open in onMount if not yet verified,
instead of opening immediately and closing after localStorage check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 16:52:48 +01:00
7d373b3aa3 i18n: internationalize all admin pages
Add full i18n coverage for the admin section — locale keys, layout nav,
users, videos, and articles pages (list, new, edit).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 16:49:30 +01:00
95fd9f48fc refactor: align article author with VideoModel, streamline selects, fix flyout inert
- Remove ArticleAuthor type; article.author now reuses VideoModel (id, artist_name, slug, avatar)
- updateArticle accepts authorId; author selectable in admin article edit page
- Article edit: single Select with bind:value + $derived selectedAuthor display
- Video edit: replace pill toggles with Select type="multiple" bind:value for models
- Video table: replace inline badge spans with Badge component
- Magazine: display artist_name throughout, author bio links to model profile
- Fix flyout aria-hidden warning: replace with inert attribute

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 16:31:41 +01:00
670c18bcb7 feat: refactor role system to is_admin flag, add Badge component, fix native dialogs
- Separate admin identity from role: viewer|model + is_admin boolean flag
- DB migration 0001_is_admin: adds column, migrates former admin role users
- Update ACL helpers, auth session, GraphQL types and all resolvers
- Admin layout guard and header links check is_admin instead of role
- Admin users table: show Admin badge next to name, remove admin from role select
- Admin user edit page: is_admin checkbox toggle
- Install shadcn Badge component; use in admin users table
- Fix duplicate photo keys in adminGetUser resolver
- Replace confirm() in /me recordings with Dialog component

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 16:14:00 +01:00
9ef490c1e5 fix: make deleteRecording a hard delete instead of soft archive
Previously deleteRecording set status to "archived", leaving the row
in the DB and visible in queries without a status filter. Now it hard-
deletes the row. Also excludes archived recordings from the default
recordings query so any pre-existing archived rows no longer appear.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 14:45:59 +01:00
193 changed files with 8844 additions and 3995 deletions

View File

@@ -7,9 +7,17 @@ on:
- develop - develop
tags: tags:
- "v*.*.*" - "v*.*.*"
paths:
- "packages/backend/**"
- "packages/types/**"
- "Dockerfile.backend"
pull_request: pull_request:
branches: branches:
- main - main
paths:
- "packages/backend/**"
- "packages/types/**"
- "Dockerfile.backend"
workflow_dispatch: workflow_dispatch:
env: env:

View File

@@ -0,0 +1,68 @@
name: Build and Push Buttplug Image
on:
push:
branches:
- main
- develop
tags:
- "v*.*.*"
paths:
- "packages/buttplug/**"
- "Dockerfile.buttplug"
- "nginx.buttplug.conf"
pull_request:
branches:
- main
paths:
- "packages/buttplug/**"
- "Dockerfile.buttplug"
- "nginx.buttplug.conf"
workflow_dispatch:
env:
REGISTRY: dev.pivoine.art
IMAGE_NAME: valknar/sexy-buttplug
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64
- name: Log in to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=sha,prefix={{branch}}-
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.buttplug
platforms: linux/amd64
push: ${{ gitea.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max

View File

@@ -7,9 +7,17 @@ on:
- develop - develop
tags: tags:
- "v*.*.*" - "v*.*.*"
paths:
- "packages/frontend/**"
- "packages/types/**"
- "Dockerfile"
pull_request: pull_request:
branches: branches:
- main - main
paths:
- "packages/frontend/**"
- "packages/types/**"
- "Dockerfile"
workflow_dispatch: workflow_dispatch:
env: env:

View File

@@ -3,7 +3,7 @@
# ============================================================================ # ============================================================================
# Base stage - shared dependencies # Base stage - shared dependencies
# ============================================================================ # ============================================================================
FROM node:22.11.0-slim AS base FROM node:22.14.0-slim AS base
# Enable corepack for pnpm # Enable corepack for pnpm
RUN npm install -g corepack@latest && corepack enable RUN npm install -g corepack@latest && corepack enable
@@ -20,48 +20,22 @@ RUN mkdir -p ./packages/frontend && \
printf 'PUBLIC_API_URL=\nPUBLIC_URL=\nPUBLIC_UMAMI_ID=\nPUBLIC_UMAMI_SCRIPT=\n' > ./packages/frontend/.env printf 'PUBLIC_API_URL=\nPUBLIC_URL=\nPUBLIC_UMAMI_ID=\nPUBLIC_UMAMI_SCRIPT=\n' > ./packages/frontend/.env
# ============================================================================ # ============================================================================
# Builder stage - compile application with Rust/WASM support # Builder stage - compile frontend
# ============================================================================ # ============================================================================
FROM base AS builder FROM base AS builder
ARG CI=false ARG CI=false
ENV CI=$CI ENV CI=$CI
# Install build dependencies for Rust and native modules
RUN apt-get update && apt-get install -y \
curl \
build-essential \
pkg-config \
libssl-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Install Rust toolchain
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
--default-toolchain stable \
--profile minimal \
--target wasm32-unknown-unknown
# Add Rust to PATH
ENV PATH="/root/.cargo/bin:${PATH}"
# Install wasm-bindgen-cli
RUN cargo install wasm-bindgen-cli
# Copy source files # Copy source files
COPY packages ./packages COPY packages ./packages
# Install all dependencies # Install all dependencies
RUN pnpm install --frozen-lockfile RUN pnpm install --frozen-lockfile
# Build packages in correct order with WASM support # Generate SvelteKit type definitions (creates .svelte-kit/tsconfig.json)
# 1. Build buttplug WASM RUN pnpm --filter @sexy.pivoine.art/frontend exec svelte-kit sync
RUN RUSTFLAGS='--cfg getrandom_backend="wasm_js" --cfg=web_sys_unstable_apis' \
pnpm --filter @sexy.pivoine.art/buttplug build:wasm
# 2. Build buttplug TypeScript # Build frontend
RUN pnpm --filter @sexy.pivoine.art/buttplug build
# 3. Build frontend
RUN pnpm --filter @sexy.pivoine.art/frontend build RUN pnpm --filter @sexy.pivoine.art/frontend build
# Prune dev dependencies for production # Prune dev dependencies for production
@@ -70,7 +44,7 @@ RUN CI=true pnpm install -rP
# ============================================================================ # ============================================================================
# Runner stage - minimal production image # Runner stage - minimal production image
# ============================================================================ # ============================================================================
FROM node:22.11.0-slim AS runner FROM node:22.14.0-slim AS runner
# Install dumb-init for proper signal handling # Install dumb-init for proper signal handling
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
@@ -91,19 +65,14 @@ COPY --from=builder --chown=node:node /app/package.json ./package.json
COPY --from=builder --chown=node:node /app/pnpm-lock.yaml ./pnpm-lock.yaml COPY --from=builder --chown=node:node /app/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=builder --chown=node:node /app/pnpm-workspace.yaml ./pnpm-workspace.yaml COPY --from=builder --chown=node:node /app/pnpm-workspace.yaml ./pnpm-workspace.yaml
# Create package directories # Create package directory
RUN mkdir -p packages/frontend packages/buttplug RUN mkdir -p packages/frontend
# Copy frontend artifacts # Copy frontend artifacts
COPY --from=builder --chown=node:node /app/packages/frontend/build ./packages/frontend/build COPY --from=builder --chown=node:node /app/packages/frontend/build ./packages/frontend/build
COPY --from=builder --chown=node:node /app/packages/frontend/node_modules ./packages/frontend/node_modules COPY --from=builder --chown=node:node /app/packages/frontend/node_modules ./packages/frontend/node_modules
COPY --from=builder --chown=node:node /app/packages/frontend/package.json ./packages/frontend/package.json COPY --from=builder --chown=node:node /app/packages/frontend/package.json ./packages/frontend/package.json
# Copy buttplug artifacts
COPY --from=builder --chown=node:node /app/packages/buttplug/dist ./packages/buttplug/dist
COPY --from=builder --chown=node:node /app/packages/buttplug/node_modules ./packages/buttplug/node_modules
COPY --from=builder --chown=node:node /app/packages/buttplug/package.json ./packages/buttplug/package.json
# Switch to non-root user # Switch to non-root user
USER node USER node

View File

@@ -3,7 +3,7 @@
# ============================================================================ # ============================================================================
# Builder stage # Builder stage
# ============================================================================ # ============================================================================
FROM node:22.11.0-slim AS builder FROM node:22.14.0-slim AS builder
RUN npm install -g corepack@latest && corepack enable RUN npm install -g corepack@latest && corepack enable
@@ -34,7 +34,7 @@ RUN pnpm rebuild argon2 sharp
# ============================================================================ # ============================================================================
# Runner stage # Runner stage
# ============================================================================ # ============================================================================
FROM node:22.11.0-slim AS runner FROM node:22.14.0-slim AS runner
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
dumb-init \ dumb-init \
@@ -55,7 +55,7 @@ COPY --from=builder --chown=node:node /app/package.json ./package.json
COPY --from=builder --chown=node:node /app/packages/backend/dist ./packages/backend/dist COPY --from=builder --chown=node:node /app/packages/backend/dist ./packages/backend/dist
COPY --from=builder --chown=node:node /app/packages/backend/node_modules ./packages/backend/node_modules COPY --from=builder --chown=node:node /app/packages/backend/node_modules ./packages/backend/node_modules
COPY --from=builder --chown=node:node /app/packages/backend/package.json ./packages/backend/package.json COPY --from=builder --chown=node:node /app/packages/backend/package.json ./packages/backend/package.json
COPY --from=builder --chown=node:node /app/packages/backend/src/migrations ./packages/backend/migrations COPY --from=builder --chown=node:node /app/packages/backend/src/migrations ./packages/backend/dist/migrations
RUN mkdir -p /data/uploads && chown node:node /data/uploads RUN mkdir -p /data/uploads && chown node:node /data/uploads

65
Dockerfile.buttplug Normal file
View File

@@ -0,0 +1,65 @@
# syntax=docker/dockerfile:1
# ============================================================================
# Builder stage - compile Rust/WASM and TypeScript
# ============================================================================
FROM node:22.14.0-slim AS builder
# Install build dependencies for Rust
RUN apt-get update && apt-get install -y \
curl \
build-essential \
pkg-config \
libssl-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Enable corepack for pnpm
RUN npm install -g corepack@latest && corepack enable
# Install Rust toolchain
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
--default-toolchain stable \
--profile minimal \
--target wasm32-unknown-unknown
ENV PATH="/root/.cargo/bin:${PATH}"
# Install wasm-bindgen-cli
RUN cargo install wasm-bindgen-cli
WORKDIR /app
# Copy workspace configuration
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
COPY packages/buttplug ./packages/buttplug
# Install dependencies
RUN pnpm install --frozen-lockfile --filter @sexy.pivoine.art/buttplug
# Build WASM
RUN RUSTFLAGS='--cfg getrandom_backend="wasm_js" --cfg=web_sys_unstable_apis' \
pnpm --filter @sexy.pivoine.art/buttplug build:wasm
# Build TypeScript
RUN pnpm --filter @sexy.pivoine.art/buttplug build
# ============================================================================
# Runner stage - nginx serving dist/ and wasm/
# ============================================================================
FROM nginx:1.27-alpine AS runner
# Remove default nginx config
RUN rm /etc/nginx/conf.d/default.conf
# Copy nginx config
COPY nginx.buttplug.conf /etc/nginx/conf.d/buttplug.conf
# Copy built artifacts
COPY --from=builder /app/packages/buttplug/dist /usr/share/nginx/html/dist
COPY --from=builder /app/packages/buttplug/wasm /usr/share/nginx/html/wasm
EXPOSE 80
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost/dist/index.js || exit 1

View File

@@ -64,6 +64,21 @@ services:
timeout: 10s timeout: 10s
retries: 3 retries: 3
start_period: 20s start_period: 20s
buttplug:
build:
context: .
dockerfile: Dockerfile.buttplug
container_name: sexy_buttplug
restart: unless-stopped
ports:
- "8080:80"
healthcheck:
test:
["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/dist/index.js"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
frontend: frontend:
build: build:
context: . context: .
@@ -78,9 +93,12 @@ services:
HOST: 0.0.0.0 HOST: 0.0.0.0
PUBLIC_API_URL: http://sexy_backend:4000 PUBLIC_API_URL: http://sexy_backend:4000
PUBLIC_URL: http://localhost:3000 PUBLIC_URL: http://localhost:3000
BUTTPLUG_URL: http://sexy_buttplug:80
depends_on: depends_on:
backend: backend:
condition: service_healthy condition: service_healthy
buttplug:
condition: service_healthy
volumes: volumes:
uploads_data: uploads_data:

View File

@@ -33,8 +33,6 @@ export default ts.config(
"error", "error",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" }, { argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
], ],
// Allow explicit any sparingly — we're adults here
"@typescript-eslint/no-explicit-any": "warn",
// Enforce consistent type imports // Enforce consistent type imports
"@typescript-eslint/consistent-type-imports": [ "@typescript-eslint/consistent-type-imports": [
"error", "error",
@@ -53,7 +51,7 @@ export default ts.config(
"**/dist/", "**/dist/",
"**/node_modules/", "**/node_modules/",
"**/migrations/", "**/migrations/",
"packages/buttplug/**", "**/wasm/",
], ],
}, },
); );

23
nginx.buttplug.conf Normal file
View File

@@ -0,0 +1,23 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
# WASM MIME type
include /etc/nginx/mime.types;
types {
application/wasm wasm;
}
# Cache JS and WASM aggressively (content-addressed by build)
location ~* \.(js|wasm)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
add_header Cross-Origin-Resource-Policy "cross-origin";
add_header Cross-Origin-Embedder-Policy "require-corp";
}
location / {
try_files $uri =404;
}
}

View File

@@ -5,11 +5,12 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build:frontend": "git pull && pnpm install && pnpm --filter @sexy.pivoine.art/frontend build", "build:frontend": "pnpm --filter @sexy.pivoine.art/frontend build",
"build:backend": "git pull && pnpm install && pnpm --filter @sexy.pivoine.art/backend build", "build:backend": "pnpm --filter @sexy.pivoine.art/backend build",
"dev:buttplug": "pnpm --filter @sexy.pivoine.art/buttplug serve",
"dev:data": "docker compose up -d postgres redis", "dev:data": "docker compose up -d postgres redis",
"dev:backend": "pnpm --filter @sexy.pivoine.art/backend dev", "dev:backend": "pnpm --filter @sexy.pivoine.art/backend dev",
"dev": "pnpm dev:data && pnpm dev:backend & pnpm --filter @sexy.pivoine.art/frontend dev", "dev": "pnpm dev:data && pnpm dev:backend & pnpm dev:buttplug & pnpm --filter @sexy.pivoine.art/frontend dev",
"lint": "eslint .", "lint": "eslint .",
"lint:fix": "eslint . --fix", "lint:fix": "eslint . --fix",
"format": "prettier --write .", "format": "prettier --write .",
@@ -22,7 +23,7 @@
"email": "valknar@pivoine.art" "email": "valknar@pivoine.art"
}, },
"license": "MIT", "license": "MIT",
"packageManager": "pnpm@10.19.0", "packageManager": "pnpm@10.31.0",
"pnpm": { "pnpm": {
"onlyBuiltDependencies": [ "onlyBuiltDependencies": [
"argon2", "argon2",

View File

@@ -14,14 +14,15 @@
"check": "tsc --noEmit" "check": "tsc --noEmit"
}, },
"dependencies": { "dependencies": {
"@sexy.pivoine.art/types": "workspace:*",
"@fastify/cookie": "^11.0.2", "@fastify/cookie": "^11.0.2",
"@fastify/cors": "^10.0.2", "@fastify/cors": "^10.0.2",
"@fastify/multipart": "^9.0.3", "@fastify/multipart": "^9.0.3",
"@fastify/static": "^8.1.1", "@fastify/static": "^8.1.1",
"@pothos/core": "^4.4.0", "@pothos/core": "^4.4.0",
"@pothos/plugin-errors": "^4.2.0", "@pothos/plugin-errors": "^4.2.0",
"@sexy.pivoine.art/types": "workspace:*",
"argon2": "^0.43.0", "argon2": "^0.43.0",
"bullmq": "^5.70.4",
"drizzle-orm": "^0.44.1", "drizzle-orm": "^0.44.1",
"fastify": "^5.4.0", "fastify": "^5.4.0",
"fluent-ffmpeg": "^2.1.3", "fluent-ffmpeg": "^2.1.3",

View File

@@ -8,6 +8,7 @@ import {
pgEnum, pgEnum,
uniqueIndex, uniqueIndex,
} from "drizzle-orm/pg-core"; } from "drizzle-orm/pg-core";
import { sql } from "drizzle-orm";
import { users } from "./users"; import { users } from "./users";
import { recordings } from "./recordings"; import { recordings } from "./recordings";
@@ -68,6 +69,11 @@ export const user_points = pgTable(
(t) => [ (t) => [
index("user_points_user_idx").on(t.user_id), index("user_points_user_idx").on(t.user_id),
index("user_points_date_idx").on(t.date_created), index("user_points_date_idx").on(t.date_created),
uniqueIndex("user_points_unique_action_recording")
.on(t.user_id, t.action, t.recording_id)
.where(
sql`"action" IN ('RECORDING_CREATE', 'RECORDING_FEATURED') AND "recording_id" IS NOT NULL`,
),
], ],
); );

View File

@@ -12,7 +12,7 @@ import {
import { users } from "./users"; import { users } from "./users";
import { videos } from "./videos"; import { videos } from "./videos";
export const recordingStatusEnum = pgEnum("recording_status", ["draft", "published", "archived"]); export const recordingStatusEnum = pgEnum("recording_status", ["draft", "published"]);
export const recordings = pgTable( export const recordings = pgTable(
"recordings", "recordings",

View File

@@ -29,6 +29,8 @@ export const users = pgTable(
role: roleEnum("role").notNull().default("viewer"), role: roleEnum("role").notNull().default("viewer"),
avatar: text("avatar").references(() => files.id, { onDelete: "set null" }), avatar: text("avatar").references(() => files.id, { onDelete: "set null" }),
banner: text("banner").references(() => files.id, { onDelete: "set null" }), banner: text("banner").references(() => files.id, { onDelete: "set null" }),
photo: text("photo").references(() => files.id, { onDelete: "set null" }),
is_admin: boolean("is_admin").notNull().default(false),
email_verified: boolean("email_verified").notNull().default(false), email_verified: boolean("email_verified").notNull().default(false),
email_verify_token: text("email_verify_token"), email_verify_token: text("email_verify_token"),
password_reset_token: text("password_reset_token"), password_reset_token: text("password_reset_token"),

View File

@@ -1,9 +1,11 @@
import type { YogaInitialContext } from "graphql-yoga"; import type { YogaInitialContext } from "graphql-yoga";
import type { FastifyRequest, FastifyReply } from "fastify"; import type { FastifyRequest, FastifyReply } from "fastify";
import type { Context } from "./builder"; import type { Context } from "./builder";
import { getSession } from "../lib/auth"; import { getSession, setSession } from "../lib/auth";
import { db } from "../db/connection"; import { db } from "../db/connection";
import { redis } from "../lib/auth"; import { redis } from "../lib/auth";
import { users } from "../db/schema/index";
import { eq } from "drizzle-orm";
type ServerContext = { type ServerContext = {
req: FastifyRequest; req: FastifyRequest;
@@ -25,7 +27,34 @@ export async function buildContext(ctx: YogaInitialContext & ServerContext): Pro
); );
const token = cookies["session_token"]; const token = cookies["session_token"];
const currentUser = token ? await getSession(token) : null; let currentUser = null;
if (token) {
const session = await getSession(token); // also slides TTL
if (session) {
const dbInstance = ctx.db || db;
const [dbUser] = await dbInstance
.select()
.from(users)
.where(eq(users.id, session.id))
.limit(1);
if (dbUser) {
currentUser = {
id: dbUser.id,
email: dbUser.email,
role: (dbUser.role === "admin" ? "viewer" : dbUser.role) as "model" | "viewer",
is_admin: dbUser.is_admin,
first_name: dbUser.first_name,
last_name: dbUser.last_name,
artist_name: dbUser.artist_name,
slug: dbUser.slug,
avatar: dbUser.avatar,
};
// Refresh cached session with up-to-date data
await setSession(token, currentUser);
}
}
}
return { return {
db: ctx.db || db, db: ctx.db || db,

View File

@@ -9,6 +9,7 @@ import "./resolvers/recordings.js";
import "./resolvers/comments.js"; import "./resolvers/comments.js";
import "./resolvers/gamification.js"; import "./resolvers/gamification.js";
import "./resolvers/stats.js"; import "./resolvers/stats.js";
import "./resolvers/queues.js";
import { builder } from "./builder"; import { builder } from "./builder";
export const schema = builder.toSchema(); export const schema = builder.toSchema();

View File

@@ -1,16 +1,18 @@
import { builder } from "../builder"; import { builder } from "../builder";
import { ArticleType } from "../types/index"; import { ArticleType, ArticleListType, AdminArticleListType } from "../types/index";
import { articles, users } from "../../db/schema/index"; import { articles, users } from "../../db/schema/index";
import { eq, and, lte, desc } from "drizzle-orm"; import { eq, and, lte, desc, asc, ilike, or, count, arrayContains, type SQL } from "drizzle-orm";
import { requireRole } from "../../lib/acl"; import { requireAdmin } from "../../lib/acl";
import type { DB } from "../../db/connection";
async function enrichArticle(db: any, article: any) { async function enrichArticle(db: DB, article: typeof articles.$inferSelect) {
let author = null; let author = null;
if (article.author) { if (article.author) {
const authorUser = await db const authorUser = await db
.select({ .select({
first_name: users.first_name, id: users.id,
last_name: users.last_name, artist_name: users.artist_name,
slug: users.slug,
avatar: users.avatar, avatar: users.avatar,
description: users.description, description: users.description,
}) })
@@ -24,30 +26,50 @@ async function enrichArticle(db: any, article: any) {
builder.queryField("articles", (t) => builder.queryField("articles", (t) =>
t.field({ t.field({
type: [ArticleType], type: ArticleListType,
args: { args: {
featured: t.arg.boolean(), featured: t.arg.boolean(),
limit: t.arg.int(), limit: t.arg.int(),
search: t.arg.string(),
category: t.arg.string(),
offset: t.arg.int(),
sortBy: t.arg.string(),
tag: t.arg.string(),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
const dateFilter = lte(articles.publish_date, new Date()); const pageSize = args.limit ?? 24;
const whereCondition = const offset = args.offset ?? 0;
args.featured !== null && args.featured !== undefined
? and(dateFilter, eq(articles.featured, args.featured))
: dateFilter;
let query = ctx.db const conditions: SQL<unknown>[] = [lte(articles.publish_date, new Date())];
.select() if (args.featured !== null && args.featured !== undefined) {
.from(articles) conditions.push(eq(articles.featured, args.featured));
.where(whereCondition) }
.orderBy(desc(articles.publish_date)); if (args.category) conditions.push(eq(articles.category, args.category));
if (args.tag) conditions.push(arrayContains(articles.tags, [args.tag]));
if (args.limit) { if (args.search) {
query = (query as any).limit(args.limit); conditions.push(
or(
ilike(articles.title, `%${args.search}%`),
ilike(articles.excerpt, `%${args.search}%`),
) as SQL<unknown>,
);
} }
const articleList = await query; const where = and(...conditions);
return Promise.all(articleList.map((article: any) => enrichArticle(ctx.db, article))); const baseQuery = ctx.db.select().from(articles).where(where);
const ordered =
args.sortBy === "name"
? baseQuery.orderBy(asc(articles.title))
: args.sortBy === "featured"
? baseQuery.orderBy(desc(articles.featured), desc(articles.publish_date))
: baseQuery.orderBy(desc(articles.publish_date));
const [articleList, totalRows] = await Promise.all([
ordered.limit(pageSize).offset(offset),
ctx.db.select({ total: count() }).from(articles).where(where),
]);
const items = await Promise.all(articleList.map((article) => enrichArticle(ctx.db, article)));
return { items, total: totalRows[0]?.total ?? 0 };
}, },
}), }),
); );
@@ -72,15 +94,65 @@ builder.queryField("article", (t) =>
}), }),
); );
builder.queryField("adminGetArticle", (t) =>
t.field({
type: ArticleType,
nullable: true,
args: {
id: t.arg.string({ required: true }),
},
resolve: async (_root, args, ctx) => {
requireAdmin(ctx);
const article = await ctx.db.select().from(articles).where(eq(articles.id, args.id)).limit(1);
if (!article[0]) return null;
return enrichArticle(ctx.db, article[0]);
},
}),
);
// ─── Admin queries & mutations ──────────────────────────────────────────────── // ─── Admin queries & mutations ────────────────────────────────────────────────
builder.queryField("adminListArticles", (t) => builder.queryField("adminListArticles", (t) =>
t.field({ t.field({
type: [ArticleType], type: AdminArticleListType,
resolve: async (_root, _args, ctx) => { args: {
requireRole(ctx, "admin"); search: t.arg.string(),
const articleList = await ctx.db.select().from(articles).orderBy(desc(articles.publish_date)); category: t.arg.string(),
return Promise.all(articleList.map((article: any) => enrichArticle(ctx.db, article))); featured: t.arg.boolean(),
limit: t.arg.int(),
offset: t.arg.int(),
},
resolve: async (_root, args, ctx) => {
requireAdmin(ctx);
const limit = args.limit ?? 50;
const offset = args.offset ?? 0;
const conditions: SQL<unknown>[] = [];
if (args.search) {
conditions.push(
or(
ilike(articles.title, `%${args.search}%`),
ilike(articles.excerpt, `%${args.search}%`),
) as SQL<unknown>,
);
}
if (args.category) conditions.push(eq(articles.category, args.category));
if (args.featured !== null && args.featured !== undefined)
conditions.push(eq(articles.featured, args.featured));
const where = conditions.length > 0 ? and(...conditions) : undefined;
const [articleList, totalRows] = await Promise.all([
ctx.db
.select()
.from(articles)
.where(where)
.orderBy(desc(articles.publish_date))
.limit(limit)
.offset(offset),
ctx.db.select({ total: count() }).from(articles).where(where),
]);
const items = await Promise.all(articleList.map((article) => enrichArticle(ctx.db, article)));
return { items, total: totalRows[0]?.total ?? 0 };
}, },
}), }),
); );
@@ -100,7 +172,7 @@ builder.mutationField("createArticle", (t) =>
publishDate: t.arg.string(), publishDate: t.arg.string(),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
const inserted = await ctx.db const inserted = await ctx.db
.insert(articles) .insert(articles)
.values({ .values({
@@ -132,19 +204,21 @@ builder.mutationField("updateArticle", (t) =>
excerpt: t.arg.string(), excerpt: t.arg.string(),
content: t.arg.string(), content: t.arg.string(),
imageId: t.arg.string(), imageId: t.arg.string(),
authorId: t.arg.string(),
tags: t.arg.stringList(), tags: t.arg.stringList(),
category: t.arg.string(), category: t.arg.string(),
featured: t.arg.boolean(), featured: t.arg.boolean(),
publishDate: t.arg.string(), publishDate: t.arg.string(),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
const updates: Record<string, unknown> = { date_updated: new Date() }; const updates: Record<string, unknown> = { date_updated: new Date() };
if (args.title !== undefined && args.title !== null) updates.title = args.title; if (args.title !== undefined && args.title !== null) updates.title = args.title;
if (args.slug !== undefined && args.slug !== null) updates.slug = args.slug; if (args.slug !== undefined && args.slug !== null) updates.slug = args.slug;
if (args.excerpt !== undefined) updates.excerpt = args.excerpt; if (args.excerpt !== undefined) updates.excerpt = args.excerpt;
if (args.content !== undefined) updates.content = args.content; if (args.content !== undefined) updates.content = args.content;
if (args.imageId !== undefined) updates.image = args.imageId; if (args.imageId !== undefined) updates.image = args.imageId;
if (args.authorId !== undefined) updates.author = args.authorId;
if (args.tags !== undefined && args.tags !== null) updates.tags = args.tags; if (args.tags !== undefined && args.tags !== null) updates.tags = args.tags;
if (args.category !== undefined) updates.category = args.category; if (args.category !== undefined) updates.category = args.category;
if (args.featured !== undefined && args.featured !== null) updates.featured = args.featured; if (args.featured !== undefined && args.featured !== null) updates.featured = args.featured;
@@ -153,7 +227,7 @@ builder.mutationField("updateArticle", (t) =>
const updated = await ctx.db const updated = await ctx.db
.update(articles) .update(articles)
.set(updates as any) .set(updates as Partial<typeof articles.$inferInsert>)
.where(eq(articles.id, args.id)) .where(eq(articles.id, args.id))
.returning(); .returning();
if (!updated[0]) return null; if (!updated[0]) return null;
@@ -169,7 +243,7 @@ builder.mutationField("deleteArticle", (t) =>
id: t.arg.string({ required: true }), id: t.arg.string({ required: true }),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
await ctx.db.delete(articles).where(eq(articles.id, args.id)); await ctx.db.delete(articles).where(eq(articles.id, args.id));
return true; return true;
}, },

View File

@@ -3,9 +3,13 @@ import { builder } from "../builder";
import { CurrentUserType } from "../types/index"; import { CurrentUserType } from "../types/index";
import { users } from "../../db/schema/index"; import { users } from "../../db/schema/index";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
interface ReplyLike {
header?: (name: string, value: string) => void;
}
import { hash, verify as verifyArgon } from "../../lib/argon"; import { hash, verify as verifyArgon } from "../../lib/argon";
import { setSession, deleteSession } from "../../lib/auth"; import { setSession, deleteSession } from "../../lib/auth";
import { sendVerification, sendPasswordReset } from "../../lib/email"; import { enqueueVerification, enqueuePasswordReset } from "../../lib/email";
import { slugify } from "../../lib/slugify"; import { slugify } from "../../lib/slugify";
import { nanoid } from "nanoid"; import { nanoid } from "nanoid";
@@ -32,7 +36,8 @@ builder.mutationField("login", (t) =>
const sessionUser = { const sessionUser = {
id: user[0].id, id: user[0].id,
email: user[0].email, email: user[0].email,
role: user[0].role, role: (user[0].role === "admin" ? "viewer" : user[0].role) as "model" | "viewer",
is_admin: user[0].is_admin,
first_name: user[0].first_name, first_name: user[0].first_name,
last_name: user[0].last_name, last_name: user[0].last_name,
artist_name: user[0].artist_name, artist_name: user[0].artist_name,
@@ -44,13 +49,8 @@ builder.mutationField("login", (t) =>
// Set session cookie // Set session cookie
const isProduction = process.env.NODE_ENV === "production"; const isProduction = process.env.NODE_ENV === "production";
const cookieValue = `session_token=${token}; HttpOnly; Path=/; SameSite=Lax; Max-Age=86400${isProduction ? "; Secure" : ""}`; const cookieValue = `session_token=${token}; HttpOnly; Path=/; SameSite=Strict; Max-Age=86400${isProduction ? "; Secure" : ""}`;
(ctx.reply as any).header?.("Set-Cookie", cookieValue); (ctx.reply as ReplyLike).header?.("Set-Cookie", cookieValue);
// For graphql-yoga response
if ((ctx as any).serverResponse) {
(ctx as any).serverResponse.setHeader("Set-Cookie", cookieValue);
}
return user[0]; return user[0];
}, },
@@ -73,8 +73,9 @@ builder.mutationField("logout", (t) =>
await deleteSession(token); await deleteSession(token);
} }
// Clear cookie // Clear cookie
const cookieValue = "session_token=; HttpOnly; Path=/; Max-Age=0"; const isProduction = process.env.NODE_ENV === "production";
(ctx.reply as any).header?.("Set-Cookie", cookieValue); const cookieValue = `session_token=; HttpOnly; Path=/; SameSite=Strict; Max-Age=0${isProduction ? "; Secure" : ""}`;
(ctx.reply as ReplyLike).header?.("Set-Cookie", cookieValue);
return true; return true;
}, },
}), }),
@@ -130,9 +131,9 @@ builder.mutationField("register", (t) =>
}); });
try { try {
await sendVerification(args.email, verifyToken); await enqueueVerification(args.email, verifyToken);
} catch (e) { } catch (e) {
console.warn("Failed to send verification email:", (e as Error).message); console.warn("Failed to enqueue verification email:", (e as Error).message);
} }
return true; return true;
}, },
@@ -189,9 +190,9 @@ builder.mutationField("requestPasswordReset", (t) =>
.where(eq(users.id, user[0].id)); .where(eq(users.id, user[0].id));
try { try {
await sendPasswordReset(args.email, token); await enqueuePasswordReset(args.email, token);
} catch (e) { } catch (e) {
console.warn("Failed to send password reset email:", (e as Error).message); console.warn("Failed to enqueue password reset email:", (e as Error).message);
} }
return true; return true;
}, },

View File

@@ -1,10 +1,10 @@
import { GraphQLError } from "graphql"; import { GraphQLError } from "graphql";
import { builder } from "../builder"; import { builder } from "../builder";
import { CommentType } from "../types/index"; import { CommentType, AdminCommentListType } from "../types/index";
import { comments, users } from "../../db/schema/index"; import { comments, users } from "../../db/schema/index";
import { eq, and, desc } from "drizzle-orm"; import { eq, and, desc, ilike, count } from "drizzle-orm";
import { awardPoints, checkAchievements } from "../../lib/gamification"; import { requireOwnerOrAdmin, requireAdmin } from "../../lib/acl";
import { requireOwnerOrAdmin } from "../../lib/acl"; import { gamificationQueue } from "../../queues/index";
builder.queryField("commentsForVideo", (t) => builder.queryField("commentsForVideo", (t) =>
t.field({ t.field({
@@ -20,7 +20,7 @@ builder.queryField("commentsForVideo", (t) =>
.orderBy(desc(comments.date_created)); .orderBy(desc(comments.date_created));
return Promise.all( return Promise.all(
commentList.map(async (c: any) => { commentList.map(async (c) => {
const user = await ctx.db const user = await ctx.db
.select({ .select({
id: users.id, id: users.id,
@@ -59,9 +59,16 @@ builder.mutationField("createCommentForVideo", (t) =>
}) })
.returning(); .returning();
// Gamification await gamificationQueue.add("awardPoints", {
await awardPoints(ctx.db, ctx.currentUser.id, "COMMENT_CREATE"); job: "awardPoints",
await checkAchievements(ctx.db, ctx.currentUser.id, "social"); userId: ctx.currentUser.id,
action: "COMMENT_CREATE",
});
await gamificationQueue.add("checkAchievements", {
job: "checkAchievements",
userId: ctx.currentUser.id,
category: "social",
});
const user = await ctx.db const user = await ctx.db
.select({ .select({
@@ -91,7 +98,68 @@ builder.mutationField("deleteComment", (t) =>
if (!comment[0]) throw new GraphQLError("Comment not found"); if (!comment[0]) throw new GraphQLError("Comment not found");
requireOwnerOrAdmin(ctx, comment[0].user_id); requireOwnerOrAdmin(ctx, comment[0].user_id);
await ctx.db.delete(comments).where(eq(comments.id, args.id)); await ctx.db.delete(comments).where(eq(comments.id, args.id));
await gamificationQueue.add("revokePoints", {
job: "revokePoints",
userId: comment[0].user_id,
action: "COMMENT_CREATE",
});
await gamificationQueue.add("checkAchievements", {
job: "checkAchievements",
userId: comment[0].user_id,
category: "social",
});
return true; return true;
}, },
}), }),
); );
builder.queryField("adminListComments", (t) =>
t.field({
type: AdminCommentListType,
args: {
search: t.arg.string(),
limit: t.arg.int(),
offset: t.arg.int(),
},
resolve: async (_root, args, ctx) => {
requireAdmin(ctx);
const limit = args.limit ?? 50;
const offset = args.offset ?? 0;
const conditions = args.search ? [ilike(comments.comment, `%${args.search}%`)] : [];
const where = conditions.length > 0 ? and(...conditions) : undefined;
const [commentList, totalRows] = await Promise.all([
ctx.db
.select()
.from(comments)
.where(where)
.orderBy(desc(comments.date_created))
.limit(limit)
.offset(offset),
ctx.db.select({ total: count() }).from(comments).where(where),
]);
const items = await Promise.all(
commentList.map(async (c) => {
const user = await ctx.db
.select({
id: users.id,
first_name: users.first_name,
last_name: users.last_name,
artist_name: users.artist_name,
avatar: users.avatar,
})
.from(users)
.where(eq(users.id, c.user_id))
.limit(1);
return { ...c, user: user[0] || null };
}),
);
return { items, total: totalRows[0]?.total ?? 0 };
},
}),
);

View File

@@ -37,7 +37,7 @@ builder.queryField("leaderboard", (t) =>
.limit(limit) .limit(limit)
.offset(offset); .offset(offset);
return entries.map((e: any, i: number) => ({ ...e, rank: offset + i + 1 })); return entries.map((e, i) => ({ ...e, rank: offset + i + 1 }));
}, },
}), }),
); );
@@ -101,8 +101,15 @@ builder.queryField("userGamification", (t) =>
return { return {
stats: stats[0] ? { ...stats[0], rank } : null, stats: stats[0] ? { ...stats[0], rank } : null,
achievements: userAchievements.map((a: any) => ({ achievements: userAchievements.map((a) => ({
...a, id: a.id!,
code: a.code!,
name: a.name!,
description: a.description!,
icon: a.icon!,
category: a.category!,
required_count: a.required_count!,
progress: a.progress!,
date_unlocked: a.date_unlocked!, date_unlocked: a.date_unlocked!,
})), })),
recent_points: recentPoints, recent_points: recentPoints,

View File

@@ -1,9 +1,10 @@
import { builder } from "../builder"; import { builder } from "../builder";
import { ModelType } from "../types/index"; import { ModelType, ModelListType } from "../types/index";
import { users, user_photos, files } from "../../db/schema/index"; import { users, user_photos, files } from "../../db/schema/index";
import { eq, and, desc } from "drizzle-orm"; import { eq, and, desc, asc, ilike, count, arrayContains, type SQL } from "drizzle-orm";
import type { DB } from "../../db/connection";
async function enrichModel(db: any, user: any) { async function enrichModel(db: DB, user: typeof users.$inferSelect) {
// Fetch photos // Fetch photos
const photoRows = await db const photoRows = await db
.select({ id: files.id, filename: files.filename }) .select({ id: files.id, filename: files.filename })
@@ -12,32 +13,42 @@ async function enrichModel(db: any, user: any) {
.where(eq(user_photos.user_id, user.id)) .where(eq(user_photos.user_id, user.id))
.orderBy(user_photos.sort); .orderBy(user_photos.sort);
return { const seen = new Set<string>();
...user, const photos = photoRows
photos: photoRows.map((p: any) => ({ id: p.id, filename: p.filename })), .filter((p) => p.id !== null && !seen.has(p.id!) && seen.add(p.id!))
}; .map((p) => ({ id: p.id!, filename: p.filename! }));
return { ...user, photos };
} }
builder.queryField("models", (t) => builder.queryField("models", (t) =>
t.field({ t.field({
type: [ModelType], type: ModelListType,
args: { args: {
featured: t.arg.boolean(), featured: t.arg.boolean(),
limit: t.arg.int(), limit: t.arg.int(),
search: t.arg.string(),
offset: t.arg.int(),
sortBy: t.arg.string(),
tag: t.arg.string(),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
let query = ctx.db const pageSize = args.limit ?? 24;
.select() const offset = args.offset ?? 0;
.from(users)
.where(eq(users.role, "model"))
.orderBy(desc(users.date_created));
if (args.limit) { const conditions: SQL<unknown>[] = [eq(users.role, "model")];
query = (query as any).limit(args.limit); if (args.search) conditions.push(ilike(users.artist_name, `%${args.search}%`));
} if (args.tag) conditions.push(arrayContains(users.tags, [args.tag]));
const modelList = await query; const order = args.sortBy === "recent" ? desc(users.date_created) : asc(users.artist_name);
return Promise.all(modelList.map((m: any) => enrichModel(ctx.db, m)));
const where = and(...conditions);
const [modelList, totalRows] = await Promise.all([
ctx.db.select().from(users).where(where).orderBy(order).limit(pageSize).offset(offset),
ctx.db.select({ total: count() }).from(users).where(where),
]);
const items = await Promise.all(modelList.map((m) => enrichModel(ctx.db, m)));
return { items, total: totalRows[0]?.total ?? 0 };
}, },
}), }),
); );

View File

@@ -0,0 +1,151 @@
import { GraphQLError } from "graphql";
import type { Job } from "bullmq";
import { builder } from "../builder.js";
import { JobType, QueueInfoType } from "../types/index.js";
import { queues } from "../../queues/index.js";
import { requireAdmin } from "../../lib/acl.js";
const JOB_STATUSES = ["waiting", "active", "completed", "failed", "delayed"] as const;
type JobStatus = (typeof JOB_STATUSES)[number];
async function toJobData(job: Job, queueName: string) {
const status = await job.getState();
return {
id: job.id ?? "",
name: job.name,
queue: queueName,
status,
data: job.data as unknown,
result: job.returnvalue as unknown,
failedReason: job.failedReason ?? null,
attemptsMade: job.attemptsMade,
createdAt: new Date(job.timestamp),
processedAt: job.processedOn ? new Date(job.processedOn) : null,
finishedAt: job.finishedOn ? new Date(job.finishedOn) : null,
progress: typeof job.progress === "number" ? job.progress : null,
};
}
builder.queryField("adminQueues", (t) =>
t.field({
type: [QueueInfoType],
resolve: async (_root, _args, ctx) => {
requireAdmin(ctx);
return Promise.all(
Object.entries(queues).map(async ([name, queue]) => {
const counts = await queue.getJobCounts(
"waiting",
"active",
"completed",
"failed",
"delayed",
"paused",
);
const isPaused = await queue.isPaused();
return {
name,
counts: {
waiting: counts.waiting ?? 0,
active: counts.active ?? 0,
completed: counts.completed ?? 0,
failed: counts.failed ?? 0,
delayed: counts.delayed ?? 0,
paused: counts.paused ?? 0,
},
isPaused,
};
}),
);
},
}),
);
builder.queryField("adminQueueJobs", (t) =>
t.field({
type: [JobType],
args: {
queue: t.arg.string({ required: true }),
status: t.arg.string(),
limit: t.arg.int(),
offset: t.arg.int(),
},
resolve: async (_root, args, ctx) => {
requireAdmin(ctx);
const queue = queues[args.queue];
if (!queue) throw new GraphQLError(`Queue "${args.queue}" not found`);
const limit = args.limit ?? 25;
const offset = args.offset ?? 0;
const statuses: JobStatus[] = args.status ? [args.status as JobStatus] : [...JOB_STATUSES];
const jobs = await queue.getJobs(statuses, offset, offset + limit - 1);
return Promise.all(jobs.map((job) => toJobData(job, args.queue)));
},
}),
);
builder.mutationField("adminRetryJob", (t) =>
t.field({
type: "Boolean",
args: {
queue: t.arg.string({ required: true }),
jobId: t.arg.string({ required: true }),
},
resolve: async (_root, args, ctx) => {
requireAdmin(ctx);
const queue = queues[args.queue];
if (!queue) throw new GraphQLError(`Queue "${args.queue}" not found`);
const job = await queue.getJob(args.jobId);
if (!job) throw new GraphQLError(`Job "${args.jobId}" not found`);
await job.retry();
return true;
},
}),
);
builder.mutationField("adminRemoveJob", (t) =>
t.field({
type: "Boolean",
args: {
queue: t.arg.string({ required: true }),
jobId: t.arg.string({ required: true }),
},
resolve: async (_root, args, ctx) => {
requireAdmin(ctx);
const queue = queues[args.queue];
if (!queue) throw new GraphQLError(`Queue "${args.queue}" not found`);
const job = await queue.getJob(args.jobId);
if (!job) throw new GraphQLError(`Job "${args.jobId}" not found`);
await job.remove();
return true;
},
}),
);
builder.mutationField("adminPauseQueue", (t) =>
t.field({
type: "Boolean",
args: { queue: t.arg.string({ required: true }) },
resolve: async (_root, args, ctx) => {
requireAdmin(ctx);
const queue = queues[args.queue];
if (!queue) throw new GraphQLError(`Queue "${args.queue}" not found`);
await queue.pause();
return true;
},
}),
);
builder.mutationField("adminResumeQueue", (t) =>
t.field({
type: "Boolean",
args: { queue: t.arg.string({ required: true }) },
resolve: async (_root, args, ctx) => {
requireAdmin(ctx);
const queue = queues[args.queue];
if (!queue) throw new GraphQLError(`Queue "${args.queue}" not found`);
await queue.resume();
return true;
},
}),
);

View File

@@ -1,10 +1,11 @@
import { GraphQLError } from "graphql"; import { GraphQLError } from "graphql";
import { builder } from "../builder"; import { builder } from "../builder";
import { RecordingType } from "../types/index"; import { RecordingType, AdminRecordingListType } from "../types/index";
import { recordings, recording_plays } from "../../db/schema/index"; import { recordings, recording_plays } from "../../db/schema/index";
import { eq, and, desc } from "drizzle-orm"; import { eq, and, desc, ilike, count, type SQL } from "drizzle-orm";
import { slugify } from "../../lib/slugify"; import { slugify } from "../../lib/slugify";
import { awardPoints, checkAchievements } from "../../lib/gamification"; import { requireAdmin } from "../../lib/acl";
import { gamificationQueue } from "../../queues/index";
builder.queryField("recordings", (t) => builder.queryField("recordings", (t) =>
t.field({ t.field({
@@ -20,7 +21,7 @@ builder.queryField("recordings", (t) =>
if (!ctx.currentUser) throw new GraphQLError("Unauthorized"); if (!ctx.currentUser) throw new GraphQLError("Unauthorized");
const conditions = [eq(recordings.user_id, ctx.currentUser.id)]; const conditions = [eq(recordings.user_id, ctx.currentUser.id)];
if (args.status) conditions.push(eq(recordings.status, args.status as any)); if (args.status) conditions.push(eq(recordings.status, args.status as "draft" | "published"));
if (args.linkedVideoId) conditions.push(eq(recordings.linked_video, args.linkedVideoId)); if (args.linkedVideoId) conditions.push(eq(recordings.linked_video, args.linkedVideoId));
const limit = args.limit || 50; const limit = args.limit || 50;
@@ -114,17 +115,25 @@ builder.mutationField("createRecording", (t) =>
user_id: ctx.currentUser.id, user_id: ctx.currentUser.id,
tags: args.tags || [], tags: args.tags || [],
linked_video: args.linkedVideoId || null, linked_video: args.linkedVideoId || null,
status: (args.status as any) || "draft", status: (args.status as "draft" | "published") || "draft",
public: false, public: false,
}) })
.returning(); .returning();
const recording = newRecording[0]; const recording = newRecording[0];
// Gamification: award points if published
if (recording.status === "published") { if (recording.status === "published") {
await awardPoints(ctx.db, ctx.currentUser.id, "RECORDING_CREATE", recording.id); await gamificationQueue.add("awardPoints", {
await checkAchievements(ctx.db, ctx.currentUser.id, "recordings"); job: "awardPoints",
userId: ctx.currentUser.id,
action: "RECORDING_CREATE",
recordingId: recording.id,
});
await gamificationQueue.add("checkAchievements", {
job: "checkAchievements",
userId: ctx.currentUser.id,
category: "recordings",
});
} }
return recording; return recording;
@@ -172,20 +181,51 @@ builder.mutationField("updateRecording", (t) =>
const updated = await ctx.db const updated = await ctx.db
.update(recordings) .update(recordings)
.set(updates as any) .set(updates as Partial<typeof recordings.$inferInsert>)
.where(eq(recordings.id, args.id)) .where(eq(recordings.id, args.id))
.returning(); .returning();
const recording = updated[0]; const recording = updated[0];
// Gamification: if newly published
if (args.status === "published" && existing[0].status !== "published") { if (args.status === "published" && existing[0].status !== "published") {
await awardPoints(ctx.db, ctx.currentUser.id, "RECORDING_CREATE", recording.id); // draft → published: award creation points
await checkAchievements(ctx.db, ctx.currentUser.id, "recordings"); await gamificationQueue.add("awardPoints", {
} job: "awardPoints",
if (args.status === "published" && recording.featured && !existing[0].featured) { userId: ctx.currentUser.id,
await awardPoints(ctx.db, ctx.currentUser.id, "RECORDING_FEATURED", recording.id); action: "RECORDING_CREATE",
await checkAchievements(ctx.db, ctx.currentUser.id, "recordings"); recordingId: recording.id,
});
await gamificationQueue.add("checkAchievements", {
job: "checkAchievements",
userId: ctx.currentUser.id,
category: "recordings",
});
} else if (args.status === "draft" && existing[0].status === "published") {
// published → draft: revoke creation points
await gamificationQueue.add("revokePoints", {
job: "revokePoints",
userId: ctx.currentUser.id,
action: "RECORDING_CREATE",
recordingId: recording.id,
});
await gamificationQueue.add("checkAchievements", {
job: "checkAchievements",
userId: ctx.currentUser.id,
category: "recordings",
});
} else if (args.status === "published" && recording.featured && !existing[0].featured) {
// newly featured while published: award featured bonus
await gamificationQueue.add("awardPoints", {
job: "awardPoints",
userId: ctx.currentUser.id,
action: "RECORDING_FEATURED",
recordingId: recording.id,
});
await gamificationQueue.add("checkAchievements", {
job: "checkAchievements",
userId: ctx.currentUser.id,
category: "recordings",
});
} }
return recording; return recording;
@@ -211,10 +251,29 @@ builder.mutationField("deleteRecording", (t) =>
if (!existing[0]) throw new GraphQLError("Recording not found"); if (!existing[0]) throw new GraphQLError("Recording not found");
if (existing[0].user_id !== ctx.currentUser.id) throw new GraphQLError("Forbidden"); if (existing[0].user_id !== ctx.currentUser.id) throw new GraphQLError("Forbidden");
await ctx.db if (existing[0].status === "published") {
.update(recordings) await gamificationQueue.add("revokePoints", {
.set({ status: "archived", date_updated: new Date() }) job: "revokePoints",
.where(eq(recordings.id, args.id)); userId: ctx.currentUser.id,
action: "RECORDING_CREATE",
recordingId: args.id,
});
if (existing[0].featured) {
await gamificationQueue.add("revokePoints", {
job: "revokePoints",
userId: ctx.currentUser.id,
action: "RECORDING_FEATURED",
recordingId: args.id,
});
}
await gamificationQueue.add("checkAchievements", {
job: "checkAchievements",
userId: ctx.currentUser.id,
category: "content",
});
}
await ctx.db.delete(recordings).where(eq(recordings.id, args.id));
return true; return true;
}, },
@@ -290,10 +349,18 @@ builder.mutationField("recordRecordingPlay", (t) =>
}) })
.returning({ id: recording_plays.id }); .returning({ id: recording_plays.id });
// Gamification
if (ctx.currentUser && recording[0].user_id !== ctx.currentUser.id) { if (ctx.currentUser && recording[0].user_id !== ctx.currentUser.id) {
await awardPoints(ctx.db, ctx.currentUser.id, "RECORDING_PLAY", args.recordingId); await gamificationQueue.add("awardPoints", {
await checkAchievements(ctx.db, ctx.currentUser.id, "playback"); job: "awardPoints",
userId: ctx.currentUser.id,
action: "RECORDING_PLAY",
recordingId: args.recordingId,
});
await gamificationQueue.add("checkAchievements", {
job: "checkAchievements",
userId: ctx.currentUser.id,
category: "playback",
});
} }
return { success: true, play_id: play[0].id }; return { success: true, play_id: play[0].id };
@@ -329,16 +396,69 @@ builder.mutationField("updateRecordingPlay", (t) =>
.where(eq(recording_plays.id, args.playId)); .where(eq(recording_plays.id, args.playId));
if (args.completed && !wasCompleted && ctx.currentUser) { if (args.completed && !wasCompleted && ctx.currentUser) {
await awardPoints( await gamificationQueue.add("awardPoints", {
ctx.db, job: "awardPoints",
ctx.currentUser.id, userId: ctx.currentUser.id,
"RECORDING_COMPLETE", action: "RECORDING_COMPLETE",
existing[0].recording_id, recordingId: existing[0].recording_id,
); });
await checkAchievements(ctx.db, ctx.currentUser.id, "playback"); await gamificationQueue.add("checkAchievements", {
job: "checkAchievements",
userId: ctx.currentUser.id,
category: "playback",
});
} }
return true; return true;
}, },
}), }),
); );
builder.queryField("adminListRecordings", (t) =>
t.field({
type: AdminRecordingListType,
args: {
search: t.arg.string(),
status: t.arg.string(),
limit: t.arg.int(),
offset: t.arg.int(),
},
resolve: async (_root, args, ctx) => {
requireAdmin(ctx);
const limit = args.limit ?? 50;
const offset = args.offset ?? 0;
const conditions: SQL<unknown>[] = [];
if (args.search) conditions.push(ilike(recordings.title, `%${args.search}%`));
if (args.status) conditions.push(eq(recordings.status, args.status as "draft" | "published"));
const where = conditions.length > 0 ? and(...conditions) : undefined;
const [rows, totalRows] = await Promise.all([
ctx.db
.select()
.from(recordings)
.where(where)
.orderBy(desc(recordings.date_created))
.limit(limit)
.offset(offset),
ctx.db.select({ total: count() }).from(recordings).where(where),
]);
return { items: rows, total: totalRows[0]?.total ?? 0 };
},
}),
);
builder.mutationField("adminDeleteRecording", (t) =>
t.field({
type: "Boolean",
args: {
id: t.arg.string({ required: true }),
},
resolve: async (_root, args, ctx) => {
requireAdmin(ctx);
await ctx.db.delete(recordings).where(eq(recordings.id, args.id));
return true;
},
}),
);

View File

@@ -2,8 +2,8 @@ import { GraphQLError } from "graphql";
import { builder } from "../builder"; import { builder } from "../builder";
import { CurrentUserType, UserType, AdminUserListType, AdminUserDetailType } from "../types/index"; import { CurrentUserType, UserType, AdminUserListType, AdminUserDetailType } from "../types/index";
import { users, user_photos, files } from "../../db/schema/index"; import { users, user_photos, files } from "../../db/schema/index";
import { eq, ilike, or, count, and } from "drizzle-orm"; import { eq, ilike, or, count, and, asc, type SQL } from "drizzle-orm";
import { requireRole } from "../../lib/acl"; import { requireAdmin } from "../../lib/acl";
builder.queryField("me", (t) => builder.queryField("me", (t) =>
t.field({ t.field({
@@ -45,6 +45,7 @@ builder.mutationField("updateProfile", (t) =>
artistName: t.arg.string(), artistName: t.arg.string(),
description: t.arg.string(), description: t.arg.string(),
tags: t.arg.stringList(), tags: t.arg.stringList(),
avatar: t.arg.string(),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
if (!ctx.currentUser) throw new GraphQLError("Unauthorized"); if (!ctx.currentUser) throw new GraphQLError("Unauthorized");
@@ -58,10 +59,11 @@ builder.mutationField("updateProfile", (t) =>
if (args.description !== undefined && args.description !== null) if (args.description !== undefined && args.description !== null)
updates.description = args.description; updates.description = args.description;
if (args.tags !== undefined && args.tags !== null) updates.tags = args.tags; if (args.tags !== undefined && args.tags !== null) updates.tags = args.tags;
if (args.avatar !== undefined) updates.avatar = args.avatar;
await ctx.db await ctx.db
.update(users) .update(users)
.set(updates as any) .set(updates as Partial<typeof users.$inferInsert>)
.where(eq(users.id, ctx.currentUser.id)); .where(eq(users.id, ctx.currentUser.id));
const updated = await ctx.db const updated = await ctx.db
@@ -86,32 +88,32 @@ builder.queryField("adminListUsers", (t) =>
offset: t.arg.int(), offset: t.arg.int(),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
const limit = args.limit ?? 50; const limit = args.limit ?? 50;
const offset = args.offset ?? 0; const offset = args.offset ?? 0;
let query = ctx.db.select().from(users); const conditions: SQL<unknown>[] = [];
let countQuery = ctx.db.select({ total: count() }).from(users);
const conditions: any[] = [];
if (args.role) { if (args.role) {
conditions.push(eq(users.role, args.role as any)); conditions.push(eq(users.role, args.role as "model" | "viewer" | "admin"));
} }
if (args.search) { if (args.search) {
const pattern = `%${args.search}%`; const pattern = `%${args.search}%`;
conditions.push(or(ilike(users.email, pattern), ilike(users.artist_name, pattern))); conditions.push(
} or(ilike(users.email, pattern), ilike(users.artist_name, pattern)) as SQL<unknown>,
);
if (conditions.length > 0) {
const where = conditions.length === 1 ? conditions[0] : and(...conditions);
query = (query as any).where(where);
countQuery = (countQuery as any).where(where);
} }
const where = conditions.length > 0 ? and(...conditions) : undefined;
const [items, totalRows] = await Promise.all([ const [items, totalRows] = await Promise.all([
(query as any).limit(limit).offset(offset), ctx.db
countQuery, .select()
.from(users)
.where(where)
.orderBy(asc(users.artist_name))
.limit(limit)
.offset(offset),
ctx.db.select({ total: count() }).from(users).where(where),
]); ]);
return { items, total: totalRows[0]?.total ?? 0 }; return { items, total: totalRows[0]?.total ?? 0 };
@@ -126,17 +128,21 @@ builder.mutationField("adminUpdateUser", (t) =>
args: { args: {
userId: t.arg.string({ required: true }), userId: t.arg.string({ required: true }),
role: t.arg.string(), role: t.arg.string(),
isAdmin: t.arg.boolean(),
firstName: t.arg.string(), firstName: t.arg.string(),
lastName: t.arg.string(), lastName: t.arg.string(),
artistName: t.arg.string(), artistName: t.arg.string(),
avatarId: t.arg.string(), avatarId: t.arg.string(),
bannerId: t.arg.string(), bannerId: t.arg.string(),
photoId: t.arg.string(),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
const updates: Record<string, unknown> = { date_updated: new Date() }; const updates: Record<string, unknown> = { date_updated: new Date() };
if (args.role !== undefined && args.role !== null) updates.role = args.role as any; if (args.role !== undefined && args.role !== null)
updates.role = args.role as "model" | "viewer" | "admin";
if (args.isAdmin !== undefined && args.isAdmin !== null) updates.is_admin = args.isAdmin;
if (args.firstName !== undefined && args.firstName !== null) if (args.firstName !== undefined && args.firstName !== null)
updates.first_name = args.firstName; updates.first_name = args.firstName;
if (args.lastName !== undefined && args.lastName !== null) updates.last_name = args.lastName; if (args.lastName !== undefined && args.lastName !== null) updates.last_name = args.lastName;
@@ -144,10 +150,11 @@ builder.mutationField("adminUpdateUser", (t) =>
updates.artist_name = args.artistName; updates.artist_name = args.artistName;
if (args.avatarId !== undefined && args.avatarId !== null) updates.avatar = args.avatarId; if (args.avatarId !== undefined && args.avatarId !== null) updates.avatar = args.avatarId;
if (args.bannerId !== undefined && args.bannerId !== null) updates.banner = args.bannerId; if (args.bannerId !== undefined && args.bannerId !== null) updates.banner = args.bannerId;
if (args.photoId !== undefined && args.photoId !== null) updates.photo = args.photoId;
const updated = await ctx.db const updated = await ctx.db
.update(users) .update(users)
.set(updates as any) .set(updates as Partial<typeof users.$inferInsert>)
.where(eq(users.id, args.userId)) .where(eq(users.id, args.userId))
.returning(); .returning();
@@ -163,7 +170,7 @@ builder.mutationField("adminDeleteUser", (t) =>
userId: t.arg.string({ required: true }), userId: t.arg.string({ required: true }),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
if (args.userId === ctx.currentUser!.id) throw new GraphQLError("Cannot delete yourself"); if (args.userId === ctx.currentUser!.id) throw new GraphQLError("Cannot delete yourself");
await ctx.db.delete(users).where(eq(users.id, args.userId)); await ctx.db.delete(users).where(eq(users.id, args.userId));
return true; return true;
@@ -179,7 +186,7 @@ builder.queryField("adminGetUser", (t) =>
userId: t.arg.string({ required: true }), userId: t.arg.string({ required: true }),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
const user = await ctx.db.select().from(users).where(eq(users.id, args.userId)).limit(1); const user = await ctx.db.select().from(users).where(eq(users.id, args.userId)).limit(1);
if (!user[0]) return null; if (!user[0]) return null;
const photoRows = await ctx.db const photoRows = await ctx.db
@@ -188,10 +195,11 @@ builder.queryField("adminGetUser", (t) =>
.leftJoin(files, eq(user_photos.file_id, files.id)) .leftJoin(files, eq(user_photos.file_id, files.id))
.where(eq(user_photos.user_id, args.userId)) .where(eq(user_photos.user_id, args.userId))
.orderBy(user_photos.sort); .orderBy(user_photos.sort);
return { const seen = new Set<string>();
...user[0], const photos = photoRows
photos: photoRows.map((p: any) => ({ id: p.id, filename: p.filename })), .filter((p) => p.id !== null && !seen.has(p.id!) && seen.add(p.id!))
}; .map((p) => ({ id: p.id!, filename: p.filename! }));
return { ...user[0], photos };
}, },
}), }),
); );
@@ -204,7 +212,7 @@ builder.mutationField("adminAddUserPhoto", (t) =>
fileId: t.arg.string({ required: true }), fileId: t.arg.string({ required: true }),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
await ctx.db.insert(user_photos).values({ user_id: args.userId, file_id: args.fileId }); await ctx.db.insert(user_photos).values({ user_id: args.userId, file_id: args.fileId });
return true; return true;
}, },
@@ -219,7 +227,7 @@ builder.mutationField("adminRemoveUserPhoto", (t) =>
fileId: t.arg.string({ required: true }), fileId: t.arg.string({ required: true }),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
await ctx.db await ctx.db
.delete(user_photos) .delete(user_photos)
.where(and(eq(user_photos.user_id, args.userId), eq(user_photos.file_id, args.fileId))); .where(and(eq(user_photos.user_id, args.userId), eq(user_photos.file_id, args.fileId)));

View File

@@ -2,6 +2,8 @@ import { GraphQLError } from "graphql";
import { builder } from "../builder"; import { builder } from "../builder";
import { import {
VideoType, VideoType,
VideoListType,
AdminVideoListType,
VideoLikeResponseType, VideoLikeResponseType,
VideoPlayResponseType, VideoPlayResponseType,
VideoLikeStatusType, VideoLikeStatusType,
@@ -14,10 +16,24 @@ import {
users, users,
files, files,
} from "../../db/schema/index"; } from "../../db/schema/index";
import { eq, and, lte, desc, inArray, count } from "drizzle-orm"; import {
import { requireRole } from "../../lib/acl"; eq,
and,
lte,
desc,
asc,
inArray,
count,
ilike,
lt,
gte,
arrayContains,
type SQL,
} from "drizzle-orm";
import { requireAdmin } from "../../lib/acl";
import type { DB } from "../../db/connection";
async function enrichVideo(db: any, video: any) { async function enrichVideo(db: DB, video: typeof videos.$inferSelect) {
// Fetch models // Fetch models
const modelRows = await db const modelRows = await db
.select({ .select({
@@ -25,6 +41,7 @@ async function enrichVideo(db: any, video: any) {
artist_name: users.artist_name, artist_name: users.artist_name,
slug: users.slug, slug: users.slug,
avatar: users.avatar, avatar: users.avatar,
description: users.description,
}) })
.from(video_models) .from(video_models)
.leftJoin(users, eq(video_models.user_id, users.id)) .leftJoin(users, eq(video_models.user_id, users.id))
@@ -47,9 +64,19 @@ async function enrichVideo(db: any, video: any) {
.from(video_plays) .from(video_plays)
.where(eq(video_plays.video_id, video.id)); .where(eq(video_plays.video_id, video.id));
const models = modelRows
.filter((m) => m.id !== null)
.map((m) => ({
id: m.id!,
artist_name: m.artist_name,
slug: m.slug,
avatar: m.avatar,
description: m.description,
}));
return { return {
...video, ...video,
models: modelRows, models,
movie_file: movieFile, movie_file: movieFile,
likes_count: likesCount[0]?.count || 0, likes_count: likesCount[0]?.count || 0,
plays_count: playsCount[0]?.count || 0, plays_count: playsCount[0]?.count || 0,
@@ -58,67 +85,93 @@ async function enrichVideo(db: any, video: any) {
builder.queryField("videos", (t) => builder.queryField("videos", (t) =>
t.field({ t.field({
type: [VideoType], type: VideoListType,
args: { args: {
modelId: t.arg.string(), modelId: t.arg.string(),
featured: t.arg.boolean(), featured: t.arg.boolean(),
limit: t.arg.int(), limit: t.arg.int(),
search: t.arg.string(),
offset: t.arg.int(),
sortBy: t.arg.string(),
duration: t.arg.string(),
tag: t.arg.string(),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
// Unauthenticated users cannot see premium videos const pageSize = args.limit ?? 24;
const premiumFilter = !ctx.currentUser ? eq(videos.premium, false) : undefined; const offset = args.offset ?? 0;
let query = ctx.db
.select({ v: videos })
.from(videos)
.where(and(lte(videos.upload_date, new Date()), premiumFilter))
.orderBy(desc(videos.upload_date));
const conditions: SQL<unknown>[] = [lte(videos.upload_date, new Date())];
if (!ctx.currentUser) conditions.push(eq(videos.premium, false));
if (args.featured !== null && args.featured !== undefined) {
conditions.push(eq(videos.featured, args.featured));
}
if (args.search) {
conditions.push(ilike(videos.title, `%${args.search}%`));
}
if (args.tag) {
conditions.push(arrayContains(videos.tags, [args.tag]));
}
if (args.modelId) { if (args.modelId) {
const videoIds = await ctx.db const videoIds = await ctx.db
.select({ video_id: video_models.video_id }) .select({ video_id: video_models.video_id })
.from(video_models) .from(video_models)
.where(eq(video_models.user_id, args.modelId)); .where(eq(video_models.user_id, args.modelId));
if (videoIds.length === 0) return { items: [], total: 0 };
if (videoIds.length === 0) return []; conditions.push(
query = ctx.db
.select({ v: videos })
.from(videos)
.where(
and(
lte(videos.upload_date, new Date()),
premiumFilter,
inArray( inArray(
videos.id, videos.id,
videoIds.map((v: any) => v.video_id), videoIds.map((v) => v.video_id),
), ),
), );
)
.orderBy(desc(videos.upload_date));
} }
if (args.featured !== null && args.featured !== undefined) { const order =
query = ctx.db args.sortBy === "most_liked"
? desc(videos.likes_count)
: args.sortBy === "most_played"
? desc(videos.plays_count)
: args.sortBy === "name"
? asc(videos.title)
: desc(videos.upload_date);
const where = and(...conditions);
// Duration filter requires JOIN to files table
if (args.duration && args.duration !== "all") {
const durationCond =
args.duration === "short"
? lt(files.duration, 600)
: args.duration === "medium"
? and(gte(files.duration, 600), lt(files.duration, 1200))
: gte(files.duration, 1200);
const fullWhere = and(where, durationCond);
const [rows, totalRows] = await Promise.all([
ctx.db
.select({ v: videos }) .select({ v: videos })
.from(videos) .from(videos)
.where( .leftJoin(files, eq(videos.movie, files.id))
and( .where(fullWhere)
lte(videos.upload_date, new Date()), .orderBy(order)
premiumFilter, .limit(pageSize)
eq(videos.featured, args.featured), .offset(offset),
), ctx.db
) .select({ total: count() })
.orderBy(desc(videos.upload_date)); .from(videos)
.leftJoin(files, eq(videos.movie, files.id))
.where(fullWhere),
]);
const videoList = rows.map((r) => r.v);
const items = await Promise.all(videoList.map((v) => enrichVideo(ctx.db, v)));
return { items, total: totalRows[0]?.total ?? 0 };
} }
if (args.limit) { const [rows, totalRows] = await Promise.all([
query = (query as any).limit(args.limit); ctx.db.select().from(videos).where(where).orderBy(order).limit(pageSize).offset(offset),
} ctx.db.select({ total: count() }).from(videos).where(where),
]);
const rows = await query; const items = await Promise.all(rows.map((v) => enrichVideo(ctx.db, v)));
const videoList = rows.map((r: any) => r.v || r); return { items, total: totalRows[0]?.total ?? 0 };
return Promise.all(videoList.map((v: any) => enrichVideo(ctx.db, v)));
}, },
}), }),
); );
@@ -148,6 +201,22 @@ builder.queryField("video", (t) =>
}), }),
); );
builder.queryField("adminGetVideo", (t) =>
t.field({
type: VideoType,
nullable: true,
args: {
id: t.arg.string({ required: true }),
},
resolve: async (_root, args, ctx) => {
requireAdmin(ctx);
const video = await ctx.db.select().from(videos).where(eq(videos.id, args.id)).limit(1);
if (!video[0]) return null;
return enrichVideo(ctx.db, video[0]);
},
}),
);
builder.queryField("videoLikeStatus", (t) => builder.queryField("videoLikeStatus", (t) =>
t.field({ t.field({
type: VideoLikeStatusType, type: VideoLikeStatusType,
@@ -365,7 +434,7 @@ builder.queryField("analytics", (t) =>
}; };
} }
const videoIds = modelVideoIds.map((v: any) => v.video_id); const videoIds = modelVideoIds.map((v) => v.video_id);
const videoList = await ctx.db.select().from(videos).where(inArray(videos.id, videoIds)); const videoList = await ctx.db.select().from(videos).where(inArray(videos.id, videoIds));
const plays = await ctx.db const plays = await ctx.db
.select() .select()
@@ -379,14 +448,14 @@ builder.queryField("analytics", (t) =>
const totalLikes = videoList.reduce((sum, v) => sum + (v.likes_count || 0), 0); const totalLikes = videoList.reduce((sum, v) => sum + (v.likes_count || 0), 0);
const totalPlays = videoList.reduce((sum, v) => sum + (v.plays_count || 0), 0); const totalPlays = videoList.reduce((sum, v) => sum + (v.plays_count || 0), 0);
const playsByDate = plays.reduce((acc: any, play) => { const playsByDate = plays.reduce((acc: Record<string, number>, play) => {
const date = new Date(play.date_created).toISOString().split("T")[0]; const date = new Date(play.date_created).toISOString().split("T")[0];
if (!acc[date]) acc[date] = 0; if (!acc[date]) acc[date] = 0;
acc[date]++; acc[date]++;
return acc; return acc;
}, {}); }, {});
const likesByDate = likes.reduce((acc: any, like) => { const likesByDate = likes.reduce((acc: Record<string, number>, like) => {
const date = new Date(like.date_created).toISOString().split("T")[0]; const date = new Date(like.date_created).toISOString().split("T")[0];
if (!acc[date]) acc[date] = 0; if (!acc[date]) acc[date] = 0;
acc[date]++; acc[date]++;
@@ -430,11 +499,39 @@ builder.queryField("analytics", (t) =>
builder.queryField("adminListVideos", (t) => builder.queryField("adminListVideos", (t) =>
t.field({ t.field({
type: [VideoType], type: AdminVideoListType,
resolve: async (_root, _args, ctx) => { args: {
requireRole(ctx, "admin"); search: t.arg.string(),
const rows = await ctx.db.select().from(videos).orderBy(desc(videos.upload_date)); premium: t.arg.boolean(),
return Promise.all(rows.map((v: any) => enrichVideo(ctx.db, v))); featured: t.arg.boolean(),
limit: t.arg.int(),
offset: t.arg.int(),
},
resolve: async (_root, args, ctx) => {
requireAdmin(ctx);
const limit = args.limit ?? 50;
const offset = args.offset ?? 0;
const conditions: SQL<unknown>[] = [];
if (args.search) conditions.push(ilike(videos.title, `%${args.search}%`));
if (args.premium !== null && args.premium !== undefined)
conditions.push(eq(videos.premium, args.premium));
if (args.featured !== null && args.featured !== undefined)
conditions.push(eq(videos.featured, args.featured));
const where = conditions.length > 0 ? and(...conditions) : undefined;
const [rows, totalRows] = await Promise.all([
ctx.db
.select()
.from(videos)
.where(where)
.orderBy(desc(videos.upload_date))
.limit(limit)
.offset(offset),
ctx.db.select({ total: count() }).from(videos).where(where),
]);
const items = await Promise.all(rows.map((v) => enrichVideo(ctx.db, v)));
return { items, total: totalRows[0]?.total ?? 0 };
}, },
}), }),
); );
@@ -454,7 +551,7 @@ builder.mutationField("createVideo", (t) =>
uploadDate: t.arg.string(), uploadDate: t.arg.string(),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
const inserted = await ctx.db const inserted = await ctx.db
.insert(videos) .insert(videos)
.values({ .values({
@@ -491,7 +588,7 @@ builder.mutationField("updateVideo", (t) =>
uploadDate: t.arg.string(), uploadDate: t.arg.string(),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
const updates: Record<string, unknown> = {}; const updates: Record<string, unknown> = {};
if (args.title !== undefined && args.title !== null) updates.title = args.title; if (args.title !== undefined && args.title !== null) updates.title = args.title;
if (args.slug !== undefined && args.slug !== null) updates.slug = args.slug; if (args.slug !== undefined && args.slug !== null) updates.slug = args.slug;
@@ -506,7 +603,7 @@ builder.mutationField("updateVideo", (t) =>
const updated = await ctx.db const updated = await ctx.db
.update(videos) .update(videos)
.set(updates as any) .set(updates as Partial<typeof videos.$inferInsert>)
.where(eq(videos.id, args.id)) .where(eq(videos.id, args.id))
.returning(); .returning();
if (!updated[0]) return null; if (!updated[0]) return null;
@@ -522,7 +619,7 @@ builder.mutationField("deleteVideo", (t) =>
id: t.arg.string({ required: true }), id: t.arg.string({ required: true }),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
await ctx.db.delete(videos).where(eq(videos.id, args.id)); await ctx.db.delete(videos).where(eq(videos.id, args.id));
return true; return true;
}, },
@@ -537,7 +634,7 @@ builder.mutationField("setVideoModels", (t) =>
userIds: t.arg.stringList({ required: true }), userIds: t.arg.stringList({ required: true }),
}, },
resolve: async (_root, args, ctx) => { resolve: async (_root, args, ctx) => {
requireRole(ctx, "admin"); requireAdmin(ctx);
await ctx.db.delete(video_models).where(eq(video_models.video_id, args.videoId)); await ctx.db.delete(video_models).where(eq(video_models.video_id, args.videoId));
if (args.userIds.length > 0) { if (args.userIds.length > 0) {
await ctx.db.insert(video_models).values( await ctx.db.insert(video_models).values(

View File

@@ -6,7 +6,6 @@ import type {
Video, Video,
ModelPhoto, ModelPhoto,
Model, Model,
ArticleAuthor,
Article, Article,
CommentUser, CommentUser,
Comment, Comment,
@@ -53,8 +52,10 @@ export const UserType = builder.objectRef<User>("User").implement({
description: t.exposeString("description", { nullable: true }), description: t.exposeString("description", { nullable: true }),
tags: t.exposeStringList("tags", { nullable: true }), tags: t.exposeStringList("tags", { nullable: true }),
role: t.exposeString("role"), role: t.exposeString("role"),
is_admin: t.exposeBoolean("is_admin"),
avatar: t.exposeString("avatar", { nullable: true }), avatar: t.exposeString("avatar", { nullable: true }),
banner: t.exposeString("banner", { nullable: true }), banner: t.exposeString("banner", { nullable: true }),
photo: t.exposeString("photo", { nullable: true }),
email_verified: t.exposeBoolean("email_verified"), email_verified: t.exposeBoolean("email_verified"),
date_created: t.expose("date_created", { type: "DateTime" }), date_created: t.expose("date_created", { type: "DateTime" }),
}), }),
@@ -72,8 +73,10 @@ export const CurrentUserType = builder.objectRef<User>("CurrentUser").implement(
description: t.exposeString("description", { nullable: true }), description: t.exposeString("description", { nullable: true }),
tags: t.exposeStringList("tags", { nullable: true }), tags: t.exposeStringList("tags", { nullable: true }),
role: t.exposeString("role"), role: t.exposeString("role"),
is_admin: t.exposeBoolean("is_admin"),
avatar: t.exposeString("avatar", { nullable: true }), avatar: t.exposeString("avatar", { nullable: true }),
banner: t.exposeString("banner", { nullable: true }), banner: t.exposeString("banner", { nullable: true }),
photo: t.exposeString("photo", { nullable: true }),
email_verified: t.exposeBoolean("email_verified"), email_verified: t.exposeBoolean("email_verified"),
date_created: t.expose("date_created", { type: "DateTime" }), date_created: t.expose("date_created", { type: "DateTime" }),
}), }),
@@ -85,6 +88,7 @@ export const VideoModelType = builder.objectRef<VideoModel>("VideoModel").implem
artist_name: t.exposeString("artist_name", { nullable: true }), artist_name: t.exposeString("artist_name", { nullable: true }),
slug: t.exposeString("slug", { nullable: true }), slug: t.exposeString("slug", { nullable: true }),
avatar: t.exposeString("avatar", { nullable: true }), avatar: t.exposeString("avatar", { nullable: true }),
description: t.exposeString("description", { nullable: true }),
}), }),
}); });
@@ -131,21 +135,13 @@ export const ModelType = builder.objectRef<Model>("Model").implement({
description: t.exposeString("description", { nullable: true }), description: t.exposeString("description", { nullable: true }),
avatar: t.exposeString("avatar", { nullable: true }), avatar: t.exposeString("avatar", { nullable: true }),
banner: t.exposeString("banner", { nullable: true }), banner: t.exposeString("banner", { nullable: true }),
photo: t.exposeString("photo", { nullable: true }),
tags: t.exposeStringList("tags", { nullable: true }), tags: t.exposeStringList("tags", { nullable: true }),
date_created: t.expose("date_created", { type: "DateTime" }), date_created: t.expose("date_created", { type: "DateTime" }),
photos: t.expose("photos", { type: [ModelPhotoType], nullable: true }), photos: t.expose("photos", { type: [ModelPhotoType], nullable: true }),
}), }),
}); });
export const ArticleAuthorType = builder.objectRef<ArticleAuthor>("ArticleAuthor").implement({
fields: (t) => ({
first_name: t.exposeString("first_name", { nullable: true }),
last_name: t.exposeString("last_name", { nullable: true }),
avatar: t.exposeString("avatar", { nullable: true }),
description: t.exposeString("description", { nullable: true }),
}),
});
export const ArticleType = builder.objectRef<Article>("Article").implement({ export const ArticleType = builder.objectRef<Article>("Article").implement({
fields: (t) => ({ fields: (t) => ({
id: t.exposeString("id"), id: t.exposeString("id"),
@@ -158,7 +154,7 @@ export const ArticleType = builder.objectRef<Article>("Article").implement({
publish_date: t.expose("publish_date", { type: "DateTime" }), publish_date: t.expose("publish_date", { type: "DateTime" }),
category: t.exposeString("category", { nullable: true }), category: t.exposeString("category", { nullable: true }),
featured: t.exposeBoolean("featured", { nullable: true }), featured: t.exposeBoolean("featured", { nullable: true }),
author: t.expose("author", { type: ArticleAuthorType, nullable: true }), author: t.expose("author", { type: VideoModelType, nullable: true }),
}), }),
}); });
@@ -337,6 +333,137 @@ export const AchievementType = builder.objectRef<Achievement>("Achievement").imp
}), }),
}); });
// --- Queue / Job types (admin only, not in shared types package) ---
type JobCounts = {
waiting: number;
active: number;
completed: number;
failed: number;
delayed: number;
paused: number;
};
type JobData = {
id: string;
name: string;
queue: string;
status: string;
data: unknown;
result: unknown;
failedReason: string | null;
attemptsMade: number;
createdAt: Date;
processedAt: Date | null;
finishedAt: Date | null;
progress: number | null;
};
type QueueInfoData = {
name: string;
counts: JobCounts;
isPaused: boolean;
};
export const JobCountsType = builder.objectRef<JobCounts>("JobCounts").implement({
fields: (t) => ({
waiting: t.exposeInt("waiting"),
active: t.exposeInt("active"),
completed: t.exposeInt("completed"),
failed: t.exposeInt("failed"),
delayed: t.exposeInt("delayed"),
paused: t.exposeInt("paused"),
}),
});
export const JobType = builder.objectRef<JobData>("Job").implement({
fields: (t) => ({
id: t.exposeString("id"),
name: t.exposeString("name"),
queue: t.exposeString("queue"),
status: t.exposeString("status"),
data: t.expose("data", { type: "JSON" }),
result: t.expose("result", { type: "JSON", nullable: true }),
failedReason: t.exposeString("failedReason", { nullable: true }),
attemptsMade: t.exposeInt("attemptsMade"),
createdAt: t.expose("createdAt", { type: "DateTime" }),
processedAt: t.expose("processedAt", { type: "DateTime", nullable: true }),
finishedAt: t.expose("finishedAt", { type: "DateTime", nullable: true }),
progress: t.exposeFloat("progress", { nullable: true }),
}),
});
export const QueueInfoType = builder.objectRef<QueueInfoData>("QueueInfo").implement({
fields: (t) => ({
name: t.exposeString("name"),
counts: t.expose("counts", { type: JobCountsType }),
isPaused: t.exposeBoolean("isPaused"),
}),
});
export const VideoListType = builder
.objectRef<{ items: Video[]; total: number }>("VideoList")
.implement({
fields: (t) => ({
items: t.expose("items", { type: [VideoType] }),
total: t.exposeInt("total"),
}),
});
export const ArticleListType = builder
.objectRef<{ items: Article[]; total: number }>("ArticleList")
.implement({
fields: (t) => ({
items: t.expose("items", { type: [ArticleType] }),
total: t.exposeInt("total"),
}),
});
export const ModelListType = builder
.objectRef<{ items: Model[]; total: number }>("ModelList")
.implement({
fields: (t) => ({
items: t.expose("items", { type: [ModelType] }),
total: t.exposeInt("total"),
}),
});
export const AdminVideoListType = builder
.objectRef<{ items: Video[]; total: number }>("AdminVideoList")
.implement({
fields: (t) => ({
items: t.expose("items", { type: [VideoType] }),
total: t.exposeInt("total"),
}),
});
export const AdminArticleListType = builder
.objectRef<{ items: Article[]; total: number }>("AdminArticleList")
.implement({
fields: (t) => ({
items: t.expose("items", { type: [ArticleType] }),
total: t.exposeInt("total"),
}),
});
export const AdminCommentListType = builder
.objectRef<{ items: Comment[]; total: number }>("AdminCommentList")
.implement({
fields: (t) => ({
items: t.expose("items", { type: [CommentType] }),
total: t.exposeInt("total"),
}),
});
export const AdminRecordingListType = builder
.objectRef<{ items: Recording[]; total: number }>("AdminRecordingList")
.implement({
fields: (t) => ({
items: t.expose("items", { type: [RecordingType] }),
total: t.exposeInt("total"),
}),
});
export const AdminUserListType = builder export const AdminUserListType = builder
.objectRef<{ items: User[]; total: number }>("AdminUserList") .objectRef<{ items: User[]; total: number }>("AdminUserList")
.implement({ .implement({
@@ -346,9 +473,7 @@ export const AdminUserListType = builder
}), }),
}); });
export const AdminUserDetailType = builder export const AdminUserDetailType = builder.objectRef<AdminUserDetail>("AdminUserDetail").implement({
.objectRef<AdminUserDetail>("AdminUserDetail")
.implement({
fields: (t) => ({ fields: (t) => ({
id: t.exposeString("id"), id: t.exposeString("id"),
email: t.exposeString("email"), email: t.exposeString("email"),
@@ -359,10 +484,12 @@ export const AdminUserDetailType = builder
description: t.exposeString("description", { nullable: true }), description: t.exposeString("description", { nullable: true }),
tags: t.exposeStringList("tags", { nullable: true }), tags: t.exposeStringList("tags", { nullable: true }),
role: t.exposeString("role"), role: t.exposeString("role"),
is_admin: t.exposeBoolean("is_admin"),
avatar: t.exposeString("avatar", { nullable: true }), avatar: t.exposeString("avatar", { nullable: true }),
banner: t.exposeString("banner", { nullable: true }), banner: t.exposeString("banner", { nullable: true }),
photo: t.exposeString("photo", { nullable: true }),
email_verified: t.exposeBoolean("email_verified"), email_verified: t.exposeBoolean("email_verified"),
date_created: t.expose("date_created", { type: "DateTime" }), date_created: t.expose("date_created", { type: "DateTime" }),
photos: t.expose("photos", { type: [ModelPhotoType] }), photos: t.expose("photos", { type: [ModelPhotoType] }),
}), }),
}); });

View File

@@ -7,19 +7,34 @@ import { createYoga } from "graphql-yoga";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { files } from "./db/schema/index"; import { files } from "./db/schema/index";
import path from "path"; import path from "path";
import { existsSync } from "fs"; import { existsSync, mkdirSync } from "fs";
import { writeFile, rm } from "fs/promises";
import sharp from "sharp"; import sharp from "sharp";
import { schema } from "./graphql/index"; import { schema } from "./graphql/index";
import { buildContext } from "./graphql/context"; import { buildContext } from "./graphql/context";
import { db } from "./db/connection"; import { db } from "./db/connection";
import { redis } from "./lib/auth"; import { redis } from "./lib/auth";
import { logger } from "./lib/logger"; import { logger } from "./lib/logger";
import { migrate } from "drizzle-orm/node-postgres/migrator";
import { startMailWorker } from "./queues/workers/mail";
import { startGamificationWorker } from "./queues/workers/gamification";
const PORT = parseInt(process.env.PORT || "4000"); const PORT = parseInt(process.env.PORT || "4000");
const UPLOAD_DIR = process.env.UPLOAD_DIR || "/data/uploads"; const UPLOAD_DIR = process.env.UPLOAD_DIR || "/data/uploads";
const CORS_ORIGIN = process.env.CORS_ORIGIN || "http://localhost:3000"; const CORS_ORIGIN = process.env.CORS_ORIGIN || "http://localhost:3000";
async function main() { async function main() {
// Run pending DB migrations before starting the server
const migrationsFolder = path.join(__dirname, "migrations");
logger.info(`Running migrations from ${migrationsFolder}`);
await migrate(db, { migrationsFolder });
logger.info("Migrations complete");
// Start background workers
startMailWorker();
startGamificationWorker();
logger.info("Queue workers started");
const fastify = Fastify({ loggerInstance: logger }); const fastify = Fastify({ loggerInstance: logger });
await fastify.register(fastifyCookie, { await fastify.register(fastifyCookie, {
@@ -120,6 +135,54 @@ async function main() {
return reply.sendFile(path.join(id, filename)); return reply.sendFile(path.join(id, filename));
}); });
// Upload a file: POST /upload (multipart, requires session)
fastify.post("/upload", async (request, reply) => {
const token = request.cookies["session_token"];
if (!token) return reply.status(401).send({ error: "Unauthorized" });
const sessionData = await redis.get(`session:${token}`);
if (!sessionData) return reply.status(401).send({ error: "Unauthorized" });
const { id: userId } = JSON.parse(sessionData);
const data = await request.file();
if (!data) return reply.status(400).send({ error: "No file provided" });
const id = crypto.randomUUID();
const filename = data.filename;
const mime_type = data.mimetype;
const dir = path.join(UPLOAD_DIR, id);
mkdirSync(dir, { recursive: true });
const buffer = await data.toBuffer();
await writeFile(path.join(dir, filename), buffer);
const [file] = await db
.insert(files)
.values({ id, filename, mime_type, filesize: buffer.byteLength, uploaded_by: userId })
.returning();
return reply.status(201).send(file);
});
// Delete a file: DELETE /assets/:id (requires session)
fastify.delete("/assets/:id", async (request, reply) => {
const token = request.cookies["session_token"];
if (!token) return reply.status(401).send({ error: "Unauthorized" });
const sessionData = await redis.get(`session:${token}`);
if (!sessionData) return reply.status(401).send({ error: "Unauthorized" });
const { id } = request.params as { id: string };
const result = await db.select().from(files).where(eq(files.id, id)).limit(1);
if (!result[0]) return reply.status(404).send({ error: "File not found" });
await db.delete(files).where(eq(files.id, id));
const dir = path.join(UPLOAD_DIR, id);
await rm(dir, { recursive: true, force: true });
return reply.status(200).send({ ok: true });
});
fastify.get("/health", async (_request, reply) => { fastify.get("/health", async (_request, reply) => {
return reply.send({ status: "ok", timestamp: new Date().toISOString() }); return reply.send({ status: "ok", timestamp: new Date().toISOString() });
}); });

View File

@@ -1,20 +1,18 @@
import { GraphQLError } from "graphql"; import { GraphQLError } from "graphql";
import type { Context } from "../graphql/builder"; import type { Context } from "../graphql/builder";
type UserRole = "viewer" | "model" | "admin";
export function requireAuth(ctx: Context): void { export function requireAuth(ctx: Context): void {
if (!ctx.currentUser) throw new GraphQLError("Unauthorized"); if (!ctx.currentUser) throw new GraphQLError("Unauthorized");
} }
export function requireRole(ctx: Context, ...roles: UserRole[]): void { export function requireAdmin(ctx: Context): void {
requireAuth(ctx); requireAuth(ctx);
if (!roles.includes(ctx.currentUser!.role)) throw new GraphQLError("Forbidden"); if (!ctx.currentUser!.is_admin) throw new GraphQLError("Forbidden");
} }
export function requireOwnerOrAdmin(ctx: Context, ownerId: string): void { export function requireOwnerOrAdmin(ctx: Context, ownerId: string): void {
requireAuth(ctx); requireAuth(ctx);
if (ctx.currentUser!.id !== ownerId && ctx.currentUser!.role !== "admin") { if (ctx.currentUser!.id !== ownerId && !ctx.currentUser!.is_admin) {
throw new GraphQLError("Forbidden"); throw new GraphQLError("Forbidden");
} }
} }

View File

@@ -3,7 +3,8 @@ import Redis from "ioredis";
export type SessionUser = { export type SessionUser = {
id: string; id: string;
email: string; email: string;
role: "model" | "viewer" | "admin"; role: "model" | "viewer";
is_admin: boolean;
first_name: string | null; first_name: string | null;
last_name: string | null; last_name: string | null;
artist_name: string | null; artist_name: string | null;
@@ -20,6 +21,8 @@ export async function setSession(token: string, user: SessionUser): Promise<void
export async function getSession(token: string): Promise<SessionUser | null> { export async function getSession(token: string): Promise<SessionUser | null> {
const data = await redis.get(`session:${token}`); const data = await redis.get(`session:${token}`);
if (!data) return null; if (!data) return null;
// Slide the expiration window on every access
await redis.expire(`session:${token}`, 86400);
return JSON.parse(data) as SessionUser; return JSON.parse(data) as SessionUser;
} }

View File

@@ -1,4 +1,5 @@
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import { mailQueue } from "../queues/index.js";
const transporter = nodemailer.createTransport({ const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST || "localhost", host: process.env.SMTP_HOST || "localhost",
@@ -32,3 +33,13 @@ export async function sendPasswordReset(email: string, token: string): Promise<v
html: `<p>Click <a href="${BASE_URL}/password/reset?token=${token}">here</a> to reset your password.</p>`, html: `<p>Click <a href="${BASE_URL}/password/reset?token=${token}">here</a> to reset your password.</p>`,
}); });
} }
const jobOpts = { attempts: 3, backoff: { type: "exponential" as const, delay: 5000 } };
export async function enqueueVerification(email: string, token: string): Promise<void> {
await mailQueue.add("sendVerification", { email, token }, jobOpts);
}
export async function enqueuePasswordReset(email: string, token: string): Promise<void> {
await mailQueue.add("sendPasswordReset", { email, token }, jobOpts);
}

View File

@@ -1,4 +1,4 @@
import { eq, sql, and, gt, isNotNull, count, sum } from "drizzle-orm"; import { eq, sql, and, gt, isNull, isNotNull, count, sum } from "drizzle-orm";
import type { DB } from "../db/connection"; import type { DB } from "../db/connection";
import { import {
user_points, user_points,
@@ -28,26 +28,62 @@ export async function awardPoints(
recordingId?: string, recordingId?: string,
): Promise<void> { ): Promise<void> {
const points = POINT_VALUES[action]; const points = POINT_VALUES[action];
await db.insert(user_points).values({ await db
.insert(user_points)
.values({
user_id: userId, user_id: userId,
action, action,
points, points,
recording_id: recordingId || null, recording_id: recordingId || null,
date_created: new Date(), date_created: new Date(),
}); })
.onConflictDoNothing();
await updateUserStats(db, userId);
}
export async function revokePoints(
db: DB,
userId: string,
action: keyof typeof POINT_VALUES,
recordingId?: string,
): Promise<void> {
const recordingCondition = recordingId
? eq(user_points.recording_id, recordingId)
: isNull(user_points.recording_id);
// When no recordingId (e.g. COMMENT_CREATE), delete only one row so each
// revoke undoes exactly one prior award.
if (!recordingId) {
const row = await db
.select({ id: user_points.id })
.from(user_points)
.where(
and(eq(user_points.user_id, userId), eq(user_points.action, action), recordingCondition),
)
.limit(1);
if (row[0]) {
await db.delete(user_points).where(eq(user_points.id, row[0].id));
}
} else {
await db
.delete(user_points)
.where(
and(eq(user_points.user_id, userId), eq(user_points.action, action), recordingCondition),
);
}
await updateUserStats(db, userId); await updateUserStats(db, userId);
} }
export async function calculateWeightedScore(db: DB, userId: string): Promise<number> { export async function calculateWeightedScore(db: DB, userId: string): Promise<number> {
const now = new Date();
const result = await db.execute(sql` const result = await db.execute(sql`
SELECT SUM( SELECT SUM(
points * EXP(-${DECAY_LAMBDA} * EXTRACT(EPOCH FROM (${now}::timestamptz - date_created)) / 86400) points * EXP(${sql.raw(String(-DECAY_LAMBDA))} * EXTRACT(EPOCH FROM (NOW() - date_created)) / 86400)
) as weighted_score ) as weighted_score
FROM user_points FROM user_points
WHERE user_id = ${userId} WHERE user_id = ${userId}
`); `);
return parseFloat((result.rows[0] as any)?.weighted_score || "0"); return parseFloat((result.rows[0] as { weighted_score?: string })?.weighted_score || "0");
} }
export async function updateUserStats(db: DB, userId: string): Promise<void> { export async function updateUserStats(db: DB, userId: string): Promise<void> {
@@ -84,7 +120,7 @@ export async function updateUserStats(db: DB, userId: string): Promise<void> {
sql`, `, sql`, `,
)}) )})
`); `);
playbacksCount = parseInt((playbacksResult.rows[0] as any)?.count || "0"); playbacksCount = parseInt((playbacksResult.rows[0] as { count?: string })?.count || "0");
} else { } else {
const playbacksResult = await db const playbacksResult = await db
.select({ count: count() }) .select({ count: count() })
@@ -96,7 +132,7 @@ export async function updateUserStats(db: DB, userId: string): Promise<void> {
const commentsResult = await db const commentsResult = await db
.select({ count: count() }) .select({ count: count() })
.from(comments) .from(comments)
.where(and(eq(comments.user_id, userId), eq(comments.collection, "recordings"))); .where(and(eq(comments.user_id, userId), eq(comments.collection, "videos")));
const commentsCount = commentsResult[0]?.count || 0; const commentsCount = commentsResult[0]?.count || 0;
const achievementsResult = await db const achievementsResult = await db
@@ -175,7 +211,9 @@ export async function checkAchievements(db: DB, userId: string, category?: strin
.update(user_achievements) .update(user_achievements)
.set({ .set({
progress, progress,
date_unlocked: isUnlocked ? existing[0].date_unlocked || new Date() : null, date_unlocked: isUnlocked
? (existing[0].date_unlocked ?? new Date())
: existing[0].date_unlocked,
}) })
.where( .where(
and( and(
@@ -242,7 +280,7 @@ async function getAchievementProgress(
WHERE rp.user_id = ${userId} WHERE rp.user_id = ${userId}
AND r.user_id != ${userId} AND r.user_id != ${userId}
`); `);
return parseInt((result.rows[0] as any)?.count || "0"); return parseInt((result.rows[0] as { count?: string })?.count || "0");
} }
if (["completionist_10", "completionist_100"].includes(code)) { if (["completionist_10", "completionist_100"].includes(code)) {
@@ -257,7 +295,7 @@ async function getAchievementProgress(
const result = await db const result = await db
.select({ count: count() }) .select({ count: count() })
.from(comments) .from(comments)
.where(and(eq(comments.user_id, userId), eq(comments.collection, "recordings"))); .where(and(eq(comments.user_id, userId), eq(comments.collection, "videos")));
return result[0]?.count || 0; return result[0]?.count || 0;
} }
@@ -293,7 +331,7 @@ async function getAchievementProgress(
WHERE rp.user_id = ${userId} AND r.user_id != ${userId} WHERE rp.user_id = ${userId} AND r.user_id != ${userId}
`); `);
const rc = recordingsResult[0]?.count || 0; const rc = recordingsResult[0]?.count || 0;
const pc = parseInt((playsResult.rows[0] as any)?.count || "0"); const pc = parseInt((playsResult.rows[0] as { count?: string })?.count || "0");
return rc >= 50 && pc >= 100 ? 1 : 0; return rc >= 50 && pc >= 100 ? 1 : 0;
} }

View File

@@ -0,0 +1,3 @@
ALTER TABLE "users" ADD COLUMN "is_admin" boolean NOT NULL DEFAULT false;--> statement-breakpoint
UPDATE "users" SET "is_admin" = true WHERE "role" = 'admin';--> statement-breakpoint
UPDATE "users" SET "role" = 'viewer' WHERE "role" = 'admin';

View File

@@ -0,0 +1,8 @@
-- Update any archived recordings to draft before removing the status
UPDATE "recordings" SET "status" = 'draft' WHERE "status" = 'archived';--> statement-breakpoint
-- Recreate enum without 'archived'
ALTER TYPE "public"."recording_status" RENAME TO "recording_status_old";--> statement-breakpoint
CREATE TYPE "public"."recording_status" AS ENUM('draft', 'published');--> statement-breakpoint
ALTER TABLE "recordings" ALTER COLUMN "status" TYPE "public"."recording_status" USING "status"::text::"public"."recording_status";--> statement-breakpoint
DROP TYPE "public"."recording_status_old";

View File

@@ -0,0 +1 @@
ALTER TABLE "users" ADD COLUMN "photo" text REFERENCES "files"("id") ON DELETE set null;

View File

@@ -0,0 +1,6 @@
-- Partial unique index: prevents duplicate RECORDING_CREATE / RECORDING_FEATURED points
-- for the same recording. RECORDING_PLAY / RECORDING_COMPLETE are excluded so a user
-- can earn play points across multiple sessions.
CREATE UNIQUE INDEX "user_points_unique_action_recording"
ON "user_points" ("user_id", "action", "recording_id")
WHERE "action" IN ('RECORDING_CREATE', 'RECORDING_FEATURED') AND "recording_id" IS NOT NULL;

View File

@@ -8,6 +8,27 @@
"when": 1772645674513, "when": 1772645674513,
"tag": "0000_pale_hellion", "tag": "0000_pale_hellion",
"breakpoints": true "breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1772645674514,
"tag": "0001_is_admin",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1741337600000,
"tag": "0002_remove_archived_recording_status",
"breakpoints": true
},
{
"idx": 3,
"version": "7",
"when": 1741420000000,
"tag": "0003_model_photo",
"breakpoints": true
} }
] ]
} }

View File

@@ -0,0 +1,16 @@
function parseRedisUrl(url: string): { host: string; port: number; password?: string } {
const parsed = new URL(url);
return {
host: parsed.hostname,
port: parseInt(parsed.port) || 6379,
password: parsed.password || undefined,
};
}
// BullMQ creates its own IORedis connections from these options.
// maxRetriesPerRequest: null is required for workers.
export const redisConnectionOpts = {
...parseRedisUrl(process.env.REDIS_URL || "redis://localhost:6379"),
maxRetriesPerRequest: null as null,
enableReadyCheck: false,
};

View File

@@ -0,0 +1,25 @@
import { Queue } from "bullmq";
import { redisConnectionOpts } from "./connection.js";
import { logger } from "../lib/logger.js";
const log = logger.child({ component: "queues" });
export const mailQueue = new Queue("mail", { connection: redisConnectionOpts });
mailQueue.on("error", (err) => {
log.error({ queue: "mail", err: err.message }, "Queue error");
});
export const gamificationQueue = new Queue("gamification", {
connection: redisConnectionOpts,
defaultJobOptions: { attempts: 3, backoff: { type: "exponential", delay: 2000 } },
});
gamificationQueue.on("error", (err) => {
log.error({ queue: "gamification", err: err.message }, "Queue error");
});
log.info("Queues initialized");
export const queues: Record<string, Queue> = {
mail: mailQueue,
gamification: gamificationQueue,
};

View File

@@ -0,0 +1,52 @@
import { Worker } from "bullmq";
import { redisConnectionOpts } from "../connection.js";
import { awardPoints, revokePoints, checkAchievements } from "../../lib/gamification.js";
import { db } from "../../db/connection.js";
import { logger } from "../../lib/logger.js";
import type { POINT_VALUES } from "../../lib/gamification.js";
const log = logger.child({ component: "gamification-worker" });
export type GamificationJobData =
| { job: "awardPoints"; userId: string; action: keyof typeof POINT_VALUES; recordingId?: string }
| { job: "revokePoints"; userId: string; action: keyof typeof POINT_VALUES; recordingId?: string }
| { job: "checkAchievements"; userId: string; category?: string };
export function startGamificationWorker(): Worker {
const worker = new Worker(
"gamification",
async (bullJob) => {
const data = bullJob.data as GamificationJobData;
log.info(
{ jobId: bullJob.id, job: data.job, userId: data.userId },
"Processing gamification job",
);
switch (data.job) {
case "awardPoints":
await awardPoints(db, data.userId, data.action, data.recordingId);
break;
case "revokePoints":
await revokePoints(db, data.userId, data.action, data.recordingId);
break;
case "checkAchievements":
await checkAchievements(db, data.userId, data.category);
break;
default:
throw new Error(`Unknown gamification job: ${(data as GamificationJobData).job}`);
}
log.info({ jobId: bullJob.id, job: data.job }, "Gamification job completed");
},
{ connection: redisConnectionOpts },
);
worker.on("failed", (bullJob, err) => {
log.error(
{ jobId: bullJob?.id, job: (bullJob?.data as GamificationJobData)?.job, err: err.message },
"Gamification job failed",
);
});
return worker;
}

View File

@@ -0,0 +1,33 @@
import { Worker } from "bullmq";
import { redisConnectionOpts } from "../connection.js";
import { sendVerification, sendPasswordReset } from "../../lib/email.js";
import { logger } from "../../lib/logger.js";
const log = logger.child({ component: "mail-worker" });
export function startMailWorker(): Worker {
const worker = new Worker(
"mail",
async (job) => {
log.info({ jobId: job.id, jobName: job.name }, `Processing mail job`);
switch (job.name) {
case "sendVerification":
await sendVerification(job.data.email as string, job.data.token as string);
break;
case "sendPasswordReset":
await sendPasswordReset(job.data.email as string, job.data.token as string);
break;
default:
throw new Error(`Unknown mail job: ${job.name}`);
}
log.info({ jobId: job.id, jobName: job.name }, `Mail job completed`);
},
{ connection: redisConnectionOpts },
);
worker.on("failed", (job, err) => {
log.error({ jobId: job?.id, jobName: job?.name, err: err.message }, `Mail job failed`);
});
return worker;
}

5
packages/buttplug/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
node_modules/
dist/
wasm/
target/
pkg/

View File

@@ -2,6 +2,7 @@
"name": "@sexy.pivoine.art/buttplug", "name": "@sexy.pivoine.art/buttplug",
"version": "1.0.0", "version": "1.0.0",
"type": "module", "type": "module",
"private": true,
"main": "./dist/index.js", "main": "./dist/index.js",
"module": "./dist/index.js", "module": "./dist/index.js",
"types": "./dist/index.d.ts", "types": "./dist/index.d.ts",
@@ -10,7 +11,8 @@
], ],
"scripts": { "scripts": {
"build": "vite build", "build": "vite build",
"build:wasm": "wasm-pack build --out-dir wasm --out-name index --target bundler --release" "build:wasm": "wasm-pack build --out-dir wasm --out-name index --target web --release",
"serve": "node serve.mjs"
}, },
"dependencies": { "dependencies": {
"eventemitter3": "^5.0.4", "eventemitter3": "^5.0.4",

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env node
// Simple static server for local development — serves dist/ and wasm/ on port 8080
import http from "http";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const PORT = process.env.PORT ?? 8080;
const MIME = {
".js": "application/javascript",
".wasm": "application/wasm",
".ts": "text/plain",
".d.ts": "text/plain",
};
http
.createServer((req, res) => {
const filePath = path.join(__dirname, decodeURIComponent(req.url.split("?")[0]));
const ext = path.extname(filePath);
fs.readFile(filePath, (err, data) => {
if (err) {
res.writeHead(404);
res.end("Not found");
return;
}
res.writeHead(200, {
"Content-Type": MIME[ext] ?? "application/octet-stream",
"Cache-Control": "no-cache",
"Cross-Origin-Resource-Policy": "cross-origin",
});
res.end(data);
});
})
.listen(PORT, () => {
console.log(`[buttplug] serving on http://localhost:${PORT}`);
});

View File

@@ -8,8 +8,8 @@
"use strict"; "use strict";
import { IButtplugClientConnector } from "./IButtplugClientConnector"; import { type IButtplugClientConnector } from "./IButtplugClientConnector";
import { ButtplugMessage } from "../core/Messages"; import { type ButtplugMessage } from "../core/Messages";
import { ButtplugBrowserWebsocketConnector } from "../utils/ButtplugBrowserWebsocketConnector"; import { ButtplugBrowserWebsocketConnector } from "../utils/ButtplugBrowserWebsocketConnector";
export class ButtplugBrowserWebsocketClientConnector export class ButtplugBrowserWebsocketClientConnector

View File

@@ -11,7 +11,7 @@
import { ButtplugLogger } from "../core/Logging"; import { ButtplugLogger } from "../core/Logging";
import { EventEmitter } from "eventemitter3"; import { EventEmitter } from "eventemitter3";
import { ButtplugClientDevice } from "./ButtplugClientDevice"; import { ButtplugClientDevice } from "./ButtplugClientDevice";
import { IButtplugClientConnector } from "./IButtplugClientConnector"; import { type IButtplugClientConnector } from "./IButtplugClientConnector";
import { ButtplugMessageSorter } from "../utils/ButtplugMessageSorter"; import { ButtplugMessageSorter } from "../utils/ButtplugMessageSorter";
import * as Messages from "../core/Messages"; import * as Messages from "../core/Messages";
import { ButtplugError, ButtplugInitError, ButtplugMessageError } from "../core/Exceptions"; import { ButtplugError, ButtplugInitError, ButtplugMessageError } from "../core/Exceptions";
@@ -158,7 +158,7 @@ export class ButtplugClient extends EventEmitter {
}; };
private parseDeviceList = (list: Messages.DeviceList) => { private parseDeviceList = (list: Messages.DeviceList) => {
for (let [_, d] of Object.entries(list.Devices)) { for (const [_, d] of Object.entries(list.Devices)) {
if (!this._devices.has(d.DeviceIndex)) { if (!this._devices.has(d.DeviceIndex)) {
const device = ButtplugClientDevice.fromMsg(d, this.sendMessageClosure); const device = ButtplugClientDevice.fromMsg(d, this.sendMessageClosure);
this._logger.Debug(`ButtplugClient: Adding Device: ${device}`); this._logger.Debug(`ButtplugClient: Adding Device: ${device}`);
@@ -168,8 +168,8 @@ export class ButtplugClient extends EventEmitter {
this._logger.Debug(`ButtplugClient: Device already added: ${d}`); this._logger.Debug(`ButtplugClient: Device already added: ${d}`);
} }
} }
for (let [index, device] of this._devices.entries()) { for (const [index, device] of this._devices.entries()) {
if (!list.Devices.hasOwnProperty(index.toString())) { if (!Object.prototype.hasOwnProperty.call(list.Devices, index.toString())) {
this._devices.delete(index); this._devices.delete(index);
this.emit("deviceremoved", device); this.emit("deviceremoved", device);
} }

View File

@@ -11,7 +11,7 @@ import * as Messages from "../core/Messages";
import { ButtplugDeviceError, ButtplugError, ButtplugMessageError } from "../core/Exceptions"; import { ButtplugDeviceError, ButtplugError, ButtplugMessageError } from "../core/Exceptions";
import { EventEmitter } from "eventemitter3"; import { EventEmitter } from "eventemitter3";
import { ButtplugClientDeviceFeature } from "./ButtplugClientDeviceFeature"; import { ButtplugClientDeviceFeature } from "./ButtplugClientDeviceFeature";
import { DeviceOutputCommand } from "./ButtplugClientDeviceCommand"; import { type DeviceOutputCommand } from "./ButtplugClientDeviceCommand";
/** /**
* Represents an abstract device, capable of taking certain kinds of messages. * Represents an abstract device, capable of taking certain kinds of messages.
@@ -105,14 +105,22 @@ export class ButtplugClientDevice extends EventEmitter {
}; };
protected isOutputValid(featureIndex: number, type: Messages.OutputType) { protected isOutputValid(featureIndex: number, type: Messages.OutputType) {
if (!this._deviceInfo.DeviceFeatures.hasOwnProperty(featureIndex.toString())) { if (
!Object.prototype.hasOwnProperty.call(
this._deviceInfo.DeviceFeatures,
featureIndex.toString(),
)
) {
throw new ButtplugDeviceError( throw new ButtplugDeviceError(
`Feature index ${featureIndex} does not exist for device ${this.name}`, `Feature index ${featureIndex} does not exist for device ${this.name}`,
); );
} }
if ( if (
this._deviceInfo.DeviceFeatures[featureIndex.toString()].Outputs !== undefined && this._deviceInfo.DeviceFeatures[featureIndex.toString()].Outputs !== undefined &&
!this._deviceInfo.DeviceFeatures[featureIndex.toString()].Outputs.hasOwnProperty(type) !Object.prototype.hasOwnProperty.call(
this._deviceInfo.DeviceFeatures[featureIndex.toString()].Outputs,
type,
)
) { ) {
throw new ButtplugDeviceError( throw new ButtplugDeviceError(
`Feature index ${featureIndex} does not support type ${type} for device ${this.name}`, `Feature index ${featureIndex} does not support type ${type} for device ${this.name}`,
@@ -139,8 +147,8 @@ export class ButtplugClientDevice extends EventEmitter {
} }
public async runOutput(cmd: DeviceOutputCommand): Promise<void> { public async runOutput(cmd: DeviceOutputCommand): Promise<void> {
let p: Promise<void>[] = []; const p: Promise<void>[] = [];
for (let f of this._features.values()) { for (const f of this._features.values()) {
if (f.hasOutput(cmd.outputType)) { if (f.hasOutput(cmd.outputType)) {
p.push(f.runOutput(cmd)); p.push(f.runOutput(cmd));
} }
@@ -164,11 +172,14 @@ export class ButtplugClientDevice extends EventEmitter {
} }
public async battery(): Promise<number> { public async battery(): Promise<number> {
let p: Promise<void>[] = []; const _p: Promise<void>[] = [];
for (let f of this._features.values()) { for (const f of this._features.values()) {
if (f.hasInput(Messages.InputType.Battery)) { if (f.hasInput(Messages.InputType.Battery)) {
// Right now, we only have one battery per device, so assume the first one we find is it. // Right now, we only have one battery per device, so assume the first one we find is it.
let response = await f.runInput(Messages.InputType.Battery, Messages.InputCommandType.Read); const response = await f.runInput(
Messages.InputType.Battery,
Messages.InputCommandType.Read,
);
if (response === undefined) { if (response === undefined) {
throw new ButtplugMessageError("Got incorrect message back."); throw new ButtplugMessageError("Got incorrect message back.");
} }

View File

@@ -14,7 +14,7 @@ class PercentOrSteps {
} }
public static createSteps(s: number): PercentOrSteps { public static createSteps(s: number): PercentOrSteps {
let v = new PercentOrSteps(); const v = new PercentOrSteps();
v._steps = s; v._steps = s;
return v; return v;
} }
@@ -24,7 +24,7 @@ class PercentOrSteps {
throw new ButtplugDeviceError(`Percent value ${p} is not in the range 0.0 <= x <= 1.0`); throw new ButtplugDeviceError(`Percent value ${p} is not in the range 0.0 <= x <= 1.0`);
} }
let v = new PercentOrSteps(); const v = new PercentOrSteps();
v._percent = p; v._percent = p;
return v; return v;
} }

View File

@@ -1,6 +1,6 @@
import { ButtplugDeviceError, ButtplugError, ButtplugMessageError } from "../core/Exceptions"; import { ButtplugDeviceError, ButtplugError, ButtplugMessageError } from "../core/Exceptions";
import * as Messages from "../core/Messages"; import * as Messages from "../core/Messages";
import { DeviceOutputCommand } from "./ButtplugClientDeviceCommand"; import { type DeviceOutputCommand } from "./ButtplugClientDeviceCommand";
export class ButtplugClientDeviceFeature { export class ButtplugClientDeviceFeature {
constructor( constructor(
@@ -26,7 +26,10 @@ export class ButtplugClientDeviceFeature {
}; };
protected isOutputValid(type: Messages.OutputType) { protected isOutputValid(type: Messages.OutputType) {
if (this._feature.Output !== undefined && !this._feature.Output.hasOwnProperty(type)) { if (
this._feature.Output !== undefined &&
!Object.prototype.hasOwnProperty.call(this._feature.Output, type)
) {
throw new ButtplugDeviceError( throw new ButtplugDeviceError(
`Feature index ${this._feature.FeatureIndex} does not support type ${type} for device ${this._deviceName}`, `Feature index ${this._feature.FeatureIndex} does not support type ${type} for device ${this._deviceName}`,
); );
@@ -34,7 +37,10 @@ export class ButtplugClientDeviceFeature {
} }
protected isInputValid(type: Messages.InputType) { protected isInputValid(type: Messages.InputType) {
if (this._feature.Input !== undefined && !this._feature.Input.hasOwnProperty(type)) { if (
this._feature.Input !== undefined &&
!Object.prototype.hasOwnProperty.call(this._feature.Input, type)
) {
throw new ButtplugDeviceError( throw new ButtplugDeviceError(
`Feature index ${this._feature.FeatureIndex} does not support type ${type} for device ${this._deviceName}`, `Feature index ${this._feature.FeatureIndex} does not support type ${type} for device ${this._deviceName}`,
); );
@@ -48,7 +54,7 @@ export class ButtplugClientDeviceFeature {
throw new ButtplugDeviceError(`${command.outputType} requires value defined`); throw new ButtplugDeviceError(`${command.outputType} requires value defined`);
} }
let type = command.outputType; const type = command.outputType;
let duration: undefined | number = undefined; let duration: undefined | number = undefined;
if (type == Messages.OutputType.HwPositionWithDuration) { if (type == Messages.OutputType.HwPositionWithDuration) {
if (command.duration === undefined) { if (command.duration === undefined) {
@@ -57,18 +63,18 @@ export class ButtplugClientDeviceFeature {
duration = command.duration; duration = command.duration;
} }
let value: number; let value: number;
let p = command.value; const p = command.value;
if (p.percent === undefined) { if (p.percent === undefined) {
// TODO Check step limits here // TODO Check step limits here
value = command.value.steps!; value = command.value.steps!;
} else { } else {
value = Math.ceil(this._feature.Output[type]!.Value![1] * p.percent); value = Math.ceil(this._feature.Output[type]!.Value![1] * p.percent);
} }
let newCommand: Messages.DeviceFeatureOutput = { Value: value, Duration: duration }; const newCommand: Messages.DeviceFeatureOutput = { Value: value, Duration: duration };
let outCommand = {}; const outCommand = {};
outCommand[type.toString()] = newCommand; outCommand[type.toString()] = newCommand;
let cmd: Messages.ButtplugMessage = { const cmd: Messages.ButtplugMessage = {
OutputCmd: { OutputCmd: {
Id: 1, Id: 1,
DeviceIndex: this._deviceIndex, DeviceIndex: this._deviceIndex,
@@ -111,14 +117,14 @@ export class ButtplugClientDeviceFeature {
public hasOutput(type: Messages.OutputType): boolean { public hasOutput(type: Messages.OutputType): boolean {
if (this._feature.Output !== undefined) { if (this._feature.Output !== undefined) {
return this._feature.Output.hasOwnProperty(type.toString()); return Object.prototype.hasOwnProperty.call(this._feature.Output, type.toString());
} }
return false; return false;
} }
public hasInput(type: Messages.InputType): boolean { public hasInput(type: Messages.InputType): boolean {
if (this._feature.Input !== undefined) { if (this._feature.Input !== undefined) {
return this._feature.Input.hasOwnProperty(type.toString()); return Object.prototype.hasOwnProperty.call(this._feature.Input, type.toString());
} }
return false; return false;
} }
@@ -126,7 +132,7 @@ export class ButtplugClientDeviceFeature {
public async runOutput(cmd: DeviceOutputCommand): Promise<void> { public async runOutput(cmd: DeviceOutputCommand): Promise<void> {
if ( if (
this._feature.Output !== undefined && this._feature.Output !== undefined &&
this._feature.Output.hasOwnProperty(cmd.outputType.toString()) Object.prototype.hasOwnProperty.call(this._feature.Output, cmd.outputType.toString())
) { ) {
return this.sendOutputCmd(cmd); return this.sendOutputCmd(cmd);
} }
@@ -139,7 +145,7 @@ export class ButtplugClientDeviceFeature {
): Promise<Messages.InputReading | undefined> { ): Promise<Messages.InputReading | undefined> {
// Make sure the requested feature is valid // Make sure the requested feature is valid
this.isInputValid(inputType); this.isInputValid(inputType);
let inputAttributes = this._feature.Input[inputType]; const inputAttributes = this._feature.Input[inputType];
console.log(this._feature.Input); console.log(this._feature.Input);
if ( if (
inputCommand === Messages.InputCommandType.Unsubscribe && inputCommand === Messages.InputCommandType.Unsubscribe &&
@@ -149,7 +155,7 @@ export class ButtplugClientDeviceFeature {
throw new ButtplugDeviceError(`${inputType} does not support command ${inputCommand}`); throw new ButtplugDeviceError(`${inputType} does not support command ${inputCommand}`);
} }
let cmd: Messages.ButtplugMessage = { const cmd: Messages.ButtplugMessage = {
InputCmd: { InputCmd: {
Id: 1, Id: 1,
DeviceIndex: this._deviceIndex, DeviceIndex: this._deviceIndex,

View File

@@ -6,8 +6,8 @@
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved. * @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
*/ */
import { ButtplugMessage } from "../core/Messages"; import { type ButtplugMessage } from "../core/Messages";
import { EventEmitter } from "eventemitter3"; import { type EventEmitter } from "eventemitter3";
export interface IButtplugClientConnector extends EventEmitter { export interface IButtplugClientConnector extends EventEmitter {
connect: () => Promise<void>; connect: () => Promise<void>;

View File

@@ -7,7 +7,7 @@
*/ */
import * as Messages from "./Messages"; import * as Messages from "./Messages";
import { ButtplugLogger } from "./Logging"; import { type ButtplugLogger } from "./Logging";
export class ButtplugError extends Error { export class ButtplugError extends Error {
public get ErrorClass(): Messages.ErrorClass { public get ErrorClass(): Messages.ErrorClass {

View File

@@ -36,7 +36,7 @@ export interface ButtplugMessage {
} }
export function msgId(msg: ButtplugMessage): number { export function msgId(msg: ButtplugMessage): number {
for (let [_, entry] of Object.entries(msg)) { for (const [_, entry] of Object.entries(msg)) {
if (entry != undefined) { if (entry != undefined) {
return entry.Id; return entry.Id;
} }
@@ -45,7 +45,7 @@ export function msgId(msg: ButtplugMessage): number {
} }
export function setMsgId(msg: ButtplugMessage, id: number) { export function setMsgId(msg: ButtplugMessage, id: number) {
for (let [_, entry] of Object.entries(msg)) { for (const [_, entry] of Object.entries(msg)) {
if (entry != undefined) { if (entry != undefined) {
entry.Id = id; entry.Id = id;
return; return;

View File

@@ -6,8 +6,8 @@
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved. * @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
*/ */
import { ButtplugMessage } from "./core/Messages"; import { type ButtplugMessage } from "./core/Messages";
import { IButtplugClientConnector } from "./client/IButtplugClientConnector"; import { type IButtplugClientConnector } from "./client/IButtplugClientConnector";
import { EventEmitter } from "eventemitter3"; import { EventEmitter } from "eventemitter3";
export * from "./client/ButtplugClient"; export * from "./client/ButtplugClient";
@@ -40,7 +40,9 @@ export class ButtplugWasmClientConnector extends EventEmitter implements IButtpl
private static maybeLoadWasm = async () => { private static maybeLoadWasm = async () => {
if (ButtplugWasmClientConnector.wasmInstance == undefined) { if (ButtplugWasmClientConnector.wasmInstance == undefined) {
ButtplugWasmClientConnector.wasmInstance = await import("../wasm/index.js"); const wasmModule = await import("../wasm/index.js");
await wasmModule.default(); // --target web requires calling init() before using exports
ButtplugWasmClientConnector.wasmInstance = wasmModule;
} }
}; };

View File

@@ -23,6 +23,7 @@ type FFICallback = js_sys::Function;
type FFICallbackContext = u32; type FFICallbackContext = u32;
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
#[allow(dead_code)]
pub struct FFICallbackContextWrapper(FFICallbackContext); pub struct FFICallbackContextWrapper(FFICallbackContext);
unsafe impl Send for FFICallbackContextWrapper { unsafe impl Send for FFICallbackContextWrapper {
@@ -50,7 +51,7 @@ pub fn send_server_message(
let buf = json.as_bytes(); let buf = json.as_bytes();
let this = JsValue::null(); let this = JsValue::null();
let uint8buf = unsafe { Uint8Array::new(&Uint8Array::view(buf)) }; let uint8buf = unsafe { Uint8Array::new(&Uint8Array::view(buf)) };
callback.call1(&this, &JsValue::from(uint8buf)); let _ = callback.call1(&this, &JsValue::from(uint8buf));
} }
} }
@@ -119,7 +120,7 @@ pub fn buttplug_client_send_json_message(
let buf = json.as_bytes(); let buf = json.as_bytes();
let this = JsValue::null(); let this = JsValue::null();
let uint8buf = unsafe { Uint8Array::new(&Uint8Array::view(buf)) }; let uint8buf = unsafe { Uint8Array::new(&Uint8Array::view(buf)) };
callback.call1(&this, &JsValue::from(uint8buf)); let _ = callback.call1(&this, &JsValue::from(uint8buf));
} }
}); });
} }

View File

@@ -9,7 +9,7 @@
"use strict"; "use strict";
import { EventEmitter } from "eventemitter3"; import { EventEmitter } from "eventemitter3";
import { ButtplugMessage } from "../core/Messages"; import { type ButtplugMessage } from "../core/Messages";
export class ButtplugBrowserWebsocketConnector extends EventEmitter { export class ButtplugBrowserWebsocketConnector extends EventEmitter {
protected _ws: WebSocket | undefined; protected _ws: WebSocket | undefined;

View File

@@ -40,7 +40,7 @@ export class ButtplugMessageSorter {
public ParseIncomingMessages(msgs: Messages.ButtplugMessage[]): Messages.ButtplugMessage[] { public ParseIncomingMessages(msgs: Messages.ButtplugMessage[]): Messages.ButtplugMessage[] {
const noMatch: Messages.ButtplugMessage[] = []; const noMatch: Messages.ButtplugMessage[] = [];
for (const x of msgs) { for (const x of msgs) {
let id = Messages.msgId(x); const id = Messages.msgId(x);
if (id !== Messages.SYSTEM_MESSAGE_ID && this._waitingMsgs.has(id)) { if (id !== Messages.SYSTEM_MESSAGE_ID && this._waitingMsgs.has(id)) {
const [res, rej] = this._waitingMsgs.get(id)!; const [res, rej] = this._waitingMsgs.get(id)!;
this._waitingMsgs.delete(id); this._waitingMsgs.delete(id);

View File

@@ -184,6 +184,7 @@ impl HardwareSpecializer for WebBluetoothHardwareSpecializer {
pub enum WebBluetoothEvent { pub enum WebBluetoothEvent {
// This is the only way we have to get our endpoints back to device creation // This is the only way we have to get our endpoints back to device creation
// right now. My god this is a mess. // right now. My god this is a mess.
#[allow(dead_code)]
Connected(Vec<Endpoint>), Connected(Vec<Endpoint>),
Disconnected, Disconnected,
} }
@@ -201,6 +202,7 @@ pub enum WebBluetoothDeviceCommand {
HardwareSubscribeCmd, HardwareSubscribeCmd,
oneshot::Sender<Result<(), ButtplugDeviceError>>, oneshot::Sender<Result<(), ButtplugDeviceError>>,
), ),
#[allow(dead_code)]
Unsubscribe( Unsubscribe(
HardwareUnsubscribeCmd, HardwareUnsubscribeCmd,
oneshot::Sender<Result<(), ButtplugDeviceError>>, oneshot::Sender<Result<(), ButtplugDeviceError>>,
@@ -271,7 +273,7 @@ async fn run_webbluetooth_loop(
//let web_btle_device = WebBluetoothDeviceImpl::new(device, char_map); //let web_btle_device = WebBluetoothDeviceImpl::new(device, char_map);
info!("device created!"); info!("device created!");
let endpoints = char_map.keys().into_iter().cloned().collect(); let endpoints = char_map.keys().into_iter().cloned().collect();
device_local_event_sender let _ = device_local_event_sender
.send(WebBluetoothEvent::Connected(endpoints)) .send(WebBluetoothEvent::Connected(endpoints))
.await; .await;
while let Some(msg) = device_command_receiver.recv().await { while let Some(msg) = device_command_receiver.recv().await {
@@ -337,6 +339,7 @@ async fn run_webbluetooth_loop(
#[derive(Debug)] #[derive(Debug)]
pub struct WebBluetoothHardware { pub struct WebBluetoothHardware {
device_command_sender: mpsc::Sender<WebBluetoothDeviceCommand>, device_command_sender: mpsc::Sender<WebBluetoothDeviceCommand>,
#[allow(dead_code)]
device_event_receiver: mpsc::Receiver<WebBluetoothEvent>, device_event_receiver: mpsc::Receiver<WebBluetoothEvent>,
event_sender: broadcast::Sender<HardwareEvent>, event_sender: broadcast::Sender<HardwareEvent>,
} }

View File

@@ -1,7 +1,6 @@
{ {
"name": "@sexy.pivoine.art/frontend", "name": "@sexy.pivoine.art/frontend",
"version": "1.0.0", "version": "1.0.0",
"author": "valknarogg",
"type": "module", "type": "module",
"private": true, "private": true,
"scripts": { "scripts": {
@@ -12,10 +11,11 @@
"check": "svelte-check --tsconfig ./tsconfig.json --threshold warning" "check": "svelte-check --tsconfig ./tsconfig.json --threshold warning"
}, },
"devDependencies": { "devDependencies": {
"@sexy.pivoine.art/buttplug": "workspace:*",
"@iconify-json/ri": "^1.2.10", "@iconify-json/ri": "^1.2.10",
"@iconify/tailwind4": "^1.2.1", "@iconify/tailwind4": "^1.2.1",
"@internationalized/date": "^3.11.0", "@internationalized/date": "^3.12.0",
"@lucide/svelte": "^0.577.0", "@lucide/svelte": "^0.561.0",
"@sveltejs/adapter-node": "^5.5.4", "@sveltejs/adapter-node": "^5.5.4",
"@sveltejs/adapter-static": "^3.0.10", "@sveltejs/adapter-static": "^3.0.10",
"@sveltejs/kit": "^2.53.4", "@sveltejs/kit": "^2.53.4",
@@ -29,7 +29,6 @@
"glob": "^13.0.6", "glob": "^13.0.6",
"mode-watcher": "^1.1.0", "mode-watcher": "^1.1.0",
"prettier-plugin-svelte": "^3.5.1", "prettier-plugin-svelte": "^3.5.1",
"super-sitemap": "^1.0.7",
"svelte": "^5.53.7", "svelte": "^5.53.7",
"svelte-check": "^4.4.4", "svelte-check": "^4.4.4",
"svelte-sonner": "^1.0.8", "svelte-sonner": "^1.0.8",
@@ -38,11 +37,9 @@
"tailwindcss": "^4.2.1", "tailwindcss": "^4.2.1",
"tw-animate-css": "^1.4.0", "tw-animate-css": "^1.4.0",
"typescript": "^5.9.3", "typescript": "^5.9.3",
"vite": "^7.3.1", "vite": "^7.3.1"
"vite-plugin-wasm": "3.5.0"
}, },
"dependencies": { "dependencies": {
"@sexy.pivoine.art/buttplug": "workspace:*",
"@sexy.pivoine.art/types": "workspace:*", "@sexy.pivoine.art/types": "workspace:*",
"graphql": "^16.11.0", "graphql": "^16.11.0",
"graphql-request": "^7.1.2", "graphql-request": "^7.1.2",

View File

@@ -3,6 +3,13 @@
@plugin "@iconify/tailwind4"; @plugin "@iconify/tailwind4";
@utility scrollbar-none {
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}
@custom-variant dark (&:where(.dark, .dark *)); @custom-variant dark (&:where(.dark, .dark *));
@custom-variant hover (&:hover); @custom-variant hover (&:hover);
@@ -194,7 +201,7 @@
--card-foreground: oklch(0.95 0.01 280); --card-foreground: oklch(0.95 0.01 280);
--border: oklch(0.2 0.05 280); --border: oklch(0.2 0.05 280);
--input: oklch(1 0 0 / 0.15); --input: oklch(1 0 0 / 0.15);
--primary: oklch(0.65 0.25 320); --primary: oklch(65.054% 0.25033 319.934);
--primary-foreground: oklch(0.98 0.01 320); --primary-foreground: oklch(0.98 0.01 320);
--secondary: oklch(0.15 0.05 260); --secondary: oklch(0.15 0.05 260);
--secondary-foreground: oklch(0.9 0.02 260); --secondary-foreground: oklch(0.9 0.02 260);

View File

@@ -9,7 +9,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com" /> <link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link <link
href="https://fonts.googleapis.com/css2?family=Dancing+Script:wght@400..700&family=Noto+Sans:ital,wght@0,100..900;1,100..900&display=swap" href="https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100..900;1,100..900&display=swap"
rel="stylesheet" rel="stylesheet"
/> />

View File

@@ -13,7 +13,7 @@
const AGE_VERIFICATION_KEY = "age-verified"; const AGE_VERIFICATION_KEY = "age-verified";
let isOpen = true; let isOpen = $state(false);
function handleAgeConfirmation() { function handleAgeConfirmation() {
localStorage.setItem(AGE_VERIFICATION_KEY, "true"); localStorage.setItem(AGE_VERIFICATION_KEY, "true");
@@ -21,9 +21,8 @@
} }
onMount(() => { onMount(() => {
const storedVerification = localStorage.getItem(AGE_VERIFICATION_KEY); if (localStorage.getItem(AGE_VERIFICATION_KEY) !== "true") {
if (storedVerification === "true") { isOpen = true;
isOpen = false;
} }
}); });
</script> </script>

View File

@@ -10,23 +10,23 @@
class="flex flex-col justify-between w-[16px] h-[10px] transform transition-all duration-300 origin-center overflow-hidden" class="flex flex-col justify-between w-[16px] h-[10px] transform transition-all duration-300 origin-center overflow-hidden"
> >
<div <div
class={`bg-white h-[2px] w-7 transform transition-all duration-300 origin-left ${isMobileMenuOpen ? "translate-x-10" : ""}`} class={`bg-foreground h-[2px] w-7 transform transition-all duration-300 origin-left ${isMobileMenuOpen ? "translate-x-10" : ""}`}
></div> ></div>
<div <div
class={`bg-white h-[2px] w-7 rounded transform transition-all duration-300 delay-75 ${isMobileMenuOpen ? "translate-x-10" : ""}`} class={`bg-foreground h-[2px] w-7 rounded transform transition-all duration-300 delay-75 ${isMobileMenuOpen ? "translate-x-10" : ""}`}
></div> ></div>
<div <div
class={`bg-white h-[2px] w-7 transform transition-all duration-300 origin-left delay-150 ${isMobileMenuOpen ? "translate-x-10" : ""}`} class={`bg-foreground h-[2px] w-7 transform transition-all duration-300 origin-left delay-150 ${isMobileMenuOpen ? "translate-x-10" : ""}`}
></div> ></div>
<div <div
class={`absolute items-center justify-between transform transition-all duration-500 top-6.5 -translate-x-10 flex w-0 ${isMobileMenuOpen ? "translate-x-0 w-12" : ""}`} class={`absolute items-center justify-between transform transition-all duration-500 top-6.5 -translate-x-10 flex w-0 ${isMobileMenuOpen ? "translate-x-0 w-12" : ""}`}
> >
<div <div
class={`absolute bg-white h-[2px] w-4 transform transition-all duration-500 rotate-0 delay-300 ${isMobileMenuOpen ? "rotate-45" : ""}`} class={`absolute bg-foreground h-[2px] w-4 transform transition-all duration-500 rotate-0 delay-300 ${isMobileMenuOpen ? "rotate-45" : ""}`}
></div> ></div>
<div <div
class={`absolute bg-white h-[2px] w-4 transform transition-all duration-500 -rotate-0 delay-300 ${isMobileMenuOpen ? "-rotate-45" : ""}`} class={`absolute bg-foreground h-[2px] w-4 transform transition-all duration-500 -rotate-0 delay-300 ${isMobileMenuOpen ? "-rotate-45" : ""}`}
></div> ></div>
</div> </div>
</div> </div>

View File

@@ -6,10 +6,9 @@
import { logout } from "$lib/services"; import { logout } from "$lib/services";
import { goto } from "$app/navigation"; import { goto } from "$app/navigation";
import { getAssetUrl } from "$lib/api"; import { getAssetUrl } from "$lib/api";
import LogoutButton from "../logout-button/logout-button.svelte";
import Separator from "../ui/separator/separator.svelte";
import { Avatar, AvatarFallback, AvatarImage } from "$lib/components/ui/avatar"; import { Avatar, AvatarFallback, AvatarImage } from "$lib/components/ui/avatar";
import { getUserInitials } from "$lib/utils"; import { getUserInitials } from "$lib/utils";
import Separator from "../ui/separator/separator.svelte";
import BurgerMenuButton from "../burger-menu-button/burger-menu-button.svelte"; import BurgerMenuButton from "../burger-menu-button/burger-menu-button.svelte";
import Logo from "../logo/logo.svelte"; import Logo from "../logo/logo.svelte";
@@ -39,7 +38,7 @@
isMobileMenuOpen = false; isMobileMenuOpen = false;
} }
function isActiveLink(link: any) { function isActiveLink(link: { name?: string; href: string }) {
return ( return (
(page.url.pathname === "/" && link === navLinks[0]) || (page.url.pathname === "/" && link === navLinks[0]) ||
(page.url.pathname.startsWith(link.href) && link !== navLinks[0]) (page.url.pathname.startsWith(link.href) && link !== navLinks[0])
@@ -48,7 +47,7 @@
</script> </script>
<header <header
class="sticky top-0 z-50 w-full bg-gradient-to-br from-card/85 via-card/90 to-card/80 backdrop-blur-xl shadow-2xl shadow-primary/20" class="sticky top-0 z-50 w-full backdrop-blur-xl shadow-[0_4px_24px_-8px_color-mix(in_oklab,var(--color-primary)_12%,transparent)] bg-card/50"
> >
<div class="container mx-auto px-4"> <div class="container mx-auto px-4">
<div class="flex items-center justify-evenly h-16"> <div class="flex items-center justify-evenly h-16">
@@ -57,7 +56,7 @@
href="/" href="/"
class="flex w-full items-center gap-3 hover:scale-105 transition-all duration-300" class="flex w-full items-center gap-3 hover:scale-105 transition-all duration-300"
> >
<Logo hideName={true} /> <Logo />
</a> </a>
<!-- Desktop Navigation --> <!-- Desktop Navigation -->
@@ -77,28 +76,14 @@
{/each} {/each}
</nav> </nav>
<!-- Desktop Auth Actions --> <!-- Auth Actions -->
{#if authStatus.authenticated} {#if authStatus.authenticated}
<div class="w-full hidden lg:flex items-center justify-end"> <div class="w-full flex items-center justify-end">
<div class="flex items-center gap-2 rounded-full bg-muted/30 p-1"> <div class="flex items-center gap-2 rounded-full bg-muted/30 p-1">
<Button <Button
variant="link" variant="link"
size="icon" size="icon"
class={`h-9 w-9 rounded-full p-0 relative text-foreground/80 group ${isActiveLink({ href: "/me" }) ? "text-foreground" : "hover:text-foreground"}`} class={`flex h-9 w-9 rounded-full p-0 relative text-foreground/80 group ${isActiveLink({ href: "/play" }) ? "text-foreground" : "hover:text-foreground"}`}
href="/me"
title={$_("header.dashboard")}
>
<span class="icon-[ri--dashboard-2-line] h-4 w-4"></span>
<span
class={`absolute -bottom-1 left-0 w-0 h-0.5 bg-gradient-to-r from-primary to-accent transition-all duration-300 ${isActiveLink({ href: "/me" }) ? "w-full" : "group-hover:w-full"}`}
></span>
<span class="sr-only">{$_("header.dashboard")}</span>
</Button>
<Button
variant="link"
size="icon"
class={`h-9 w-9 rounded-full p-0 relative text-foreground/80 group ${isActiveLink({ href: "/play" }) ? "text-foreground" : "hover:text-foreground"}`}
href="/play" href="/play"
title={$_("header.play")} title={$_("header.play")}
> >
@@ -109,11 +94,11 @@
<span class="sr-only">{$_("header.play")}</span> <span class="sr-only">{$_("header.play")}</span>
</Button> </Button>
{#if authStatus.user?.role === "admin"} {#if authStatus.user?.is_admin}
<Button <Button
variant="link" variant="link"
size="icon" size="icon"
class={`h-9 w-9 rounded-full p-0 relative text-foreground/80 group ${isActiveLink({ href: "/admin" }) ? "text-foreground" : "hover:text-foreground"}`} class={`flex h-9 w-9 rounded-full p-0 relative text-foreground/80 group ${isActiveLink({ href: "/admin" }) ? "text-foreground" : "hover:text-foreground"}`}
href="/admin/users" href="/admin/users"
title="Admin" title="Admin"
> >
@@ -125,32 +110,38 @@
</Button> </Button>
{/if} {/if}
<Separator orientation="vertical" class="mx-1 h-6 bg-border/50" /> <Separator orientation="vertical" class="hidden lg:block mx-1 h-6 bg-border/50" />
<LogoutButton <a href="/me" class="flex items-center gap-2 px-1 hover:opacity-80 transition-opacity">
user={{ <Avatar class="h-7 w-7 ring-2 ring-primary/20">
name: <AvatarImage
authStatus.user!.artist_name || authStatus.user!.email.split("@")[0] || "User", src={getAssetUrl(authStatus.user!.avatar, "mini")!}
avatar: getAssetUrl(authStatus.user!.avatar, "mini")!, alt={authStatus.user!.artist_name || authStatus.user!.email}
email: authStatus.user!.email,
}}
onLogout={handleLogout}
/> />
</div> <AvatarFallback
</div> class="bg-gradient-to-br from-primary to-accent text-primary-foreground text-xs font-semibold"
{:else}
<div class="hidden lg:flex w-full items-center justify-end gap-4">
<Button variant="outline" class="font-medium" href="/login">{$_("header.login")}</Button>
<Button
href="/signup"
class="bg-gradient-to-r from-primary to-accent hover:from-primary/90 hover:to-accent/90 font-medium"
>{$_("header.signup")}</Button
> >
</div> {getUserInitials(authStatus.user!.artist_name || authStatus.user!.email)}
{/if} </AvatarFallback>
</Avatar>
<span
class="hidden lg:inline text-sm font-medium text-foreground/90 max-w-24 truncate"
>
{authStatus.user!.artist_name || authStatus.user!.email.split("@")[0]}
</span>
</a>
<!-- Burger button — mobile/tablet only --> <Button
<div class="lg:hidden ml-auto"> variant="link"
size="icon"
class="hidden lg:flex h-9 w-9 rounded-full p-0 relative text-foreground/80 group hover:text-destructive"
onclick={handleLogout}
title={$_("header.logout")}
>
<span class="icon-[ri--logout-circle-r-line] h-4 w-4"></span>
</Button>
</div>
<div class="lg:hidden ml-2">
<BurgerMenuButton <BurgerMenuButton
label={$_("header.navigation")} label={$_("header.navigation")}
bind:isMobileMenuOpen bind:isMobileMenuOpen
@@ -158,11 +149,31 @@
/> />
</div> </div>
</div> </div>
{:else}
<div class="w-full flex items-center justify-end gap-2">
<div class="flex gap-4">
<Button variant="outline" class="font-medium" href="/login">{$_("header.login")}</Button
>
<Button
href="/signup"
class="bg-gradient-to-r from-primary to-accent hover:from-primary/90 hover:to-accent/90 font-medium"
>{$_("header.signup")}</Button
>
</div>
<div class="lg:hidden ml-2">
<BurgerMenuButton
label={$_("header.navigation")}
bind:isMobileMenuOpen
onclick={() => (isMobileMenuOpen = !isMobileMenuOpen)}
/>
</div>
</div>
{/if}
</div>
</div> </div>
</header> </header>
<!-- Backdrop --> <!-- Backdrop -->
<!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions a11y_no_noninteractive_element_interactions -->
<div <div
role="presentation" role="presentation"
class={`fixed inset-0 z-40 bg-black/60 backdrop-blur-sm transition-opacity duration-300 lg:hidden ${isMobileMenuOpen ? "opacity-100 pointer-events-auto" : "opacity-0 pointer-events-none"}`} class={`fixed inset-0 z-40 bg-black/60 backdrop-blur-sm transition-opacity duration-300 lg:hidden ${isMobileMenuOpen ? "opacity-100 pointer-events-auto" : "opacity-0 pointer-events-none"}`}
@@ -172,41 +183,43 @@
<!-- Flyout panel --> <!-- Flyout panel -->
<div <div
class={`fixed inset-y-0 left-0 z-50 w-80 max-w-[85vw] bg-card/95 backdrop-blur-xl shadow-2xl shadow-primary/20 border-r border-border/30 transform transition-transform duration-300 ease-in-out lg:hidden overflow-y-auto flex flex-col ${isMobileMenuOpen ? "translate-x-0" : "-translate-x-full"}`} class={`fixed inset-y-0 left-0 z-50 w-80 max-w-[85vw] bg-card/95 backdrop-blur-xl shadow-2xl shadow-primary/20 border-r border-border/30 transform transition-transform duration-300 ease-in-out lg:hidden overflow-y-auto flex flex-col ${isMobileMenuOpen ? "translate-x-0" : "-translate-x-full"}`}
aria-hidden={!isMobileMenuOpen} inert={!isMobileMenuOpen || undefined}
> >
<!-- Panel header --> <!-- Panel header -->
<div class="flex items-center px-5 h-16 shrink-0 border-b border-border/30"> <div class="flex items-center px-5 h-16 shrink-0 border-b border-border/30">
<Logo hideName={true} /> <Logo />
</div> </div>
<div class="flex-1 py-6 px-5 space-y-6"> <div class="flex-1 py-6 px-5 space-y-6">
<!-- User Profile Card --> <!-- User card -->
{#if authStatus.authenticated} {#if authStatus.authenticated}
<div <div class="flex items-center gap-3 rounded-xl border border-border/40 bg-card/50 px-4 py-3">
class="relative overflow-hidden rounded-2xl border border-border/50 bg-gradient-to-br from-card to-card/50 p-4" <Avatar class="h-10 w-10 ring-2 ring-primary/20 shrink-0">
>
<div class="absolute inset-0 bg-gradient-to-br from-primary/5 to-accent/5"></div>
<div class="relative flex items-center gap-3">
<Avatar class="h-9 w-9 ring-2 ring-primary/30">
<AvatarImage <AvatarImage
src={getAssetUrl(authStatus.user!.avatar, "mini")} src={getAssetUrl(authStatus.user!.avatar, "mini")!}
alt={authStatus.user!.artist_name} alt={authStatus.user!.artist_name || authStatus.user!.email}
/> />
<AvatarFallback <AvatarFallback
class="bg-gradient-to-br from-primary to-accent text-primary-foreground font-semibold" class="bg-gradient-to-br from-primary to-accent text-primary-foreground text-sm font-semibold"
> >
{getUserInitials(authStatus.user!.artist_name)} {getUserInitials(authStatus.user!.artist_name || authStatus.user!.email)}
</AvatarFallback> </AvatarFallback>
</Avatar> </Avatar>
<div class="flex flex-1 flex-col min-w-0"> <div class="flex flex-col min-w-0 flex-1">
<p class="text-sm font-semibold text-foreground truncate"> <span class="text-sm font-semibold text-foreground truncate">
{authStatus.user!.artist_name || authStatus.user!.email.split("@")[0]} {authStatus.user!.artist_name || authStatus.user!.email.split("@")[0]}
</p> </span>
<p class="text-xs text-muted-foreground truncate"> <span class="text-xs text-muted-foreground truncate">{authStatus.user!.email}</span>
{authStatus.user!.email}
</p>
</div>
</div> </div>
<Button
variant="ghost"
size="icon"
class="h-8 w-8 rounded-full text-muted-foreground hover:text-destructive hover:bg-destructive/10 shrink-0"
onclick={handleLogout}
title={$_("header.logout")}
>
<span class="icon-[ri--logout-circle-r-line] h-4 w-4"></span>
</Button>
</div> </div>
{/if} {/if}
@@ -278,7 +291,7 @@
<span class="icon-[ri--arrow-right-s-line] h-4 w-4 text-muted-foreground"></span> <span class="icon-[ri--arrow-right-s-line] h-4 w-4 text-muted-foreground"></span>
</a> </a>
{#if authStatus.user?.role === "admin"} {#if authStatus.user?.is_admin}
<a <a
class={`flex items-center gap-3 rounded-xl border px-4 py-3 transition-all duration-200 group hover:border-primary/30 hover:bg-primary/5 ${isActiveLink({ href: "/admin" }) ? "border-primary/40 bg-primary/8" : "border-border/40 bg-card/50"}`} class={`flex items-center gap-3 rounded-xl border px-4 py-3 transition-all duration-200 group hover:border-primary/30 hover:bg-primary/5 ${isActiveLink({ href: "/admin" }) ? "border-primary/40 bg-primary/8" : "border-border/40 bg-card/50"}`}
href="/admin/users" href="/admin/users"
@@ -339,22 +352,5 @@
{/if} {/if}
</div> </div>
</div> </div>
{#if authStatus.authenticated}
<button
class="cursor-pointer flex w-full items-center gap-3 rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-3 transition-all duration-200 hover:bg-destructive/10 hover:border-destructive/30 group"
onclick={handleLogout}
>
<div
class="flex h-8 w-8 items-center justify-center rounded-lg bg-destructive/10 group-hover:bg-destructive/20 transition-colors"
>
<span class="icon-[ri--logout-circle-r-line] h-4 w-4 text-destructive"></span>
</div>
<div class="flex flex-1 flex-col gap-0.5 text-left">
<span class="text-sm font-medium text-foreground">{$_("header.logout")}</span>
<span class="text-xs text-muted-foreground">{$_("header.logout_hint")}</span>
</div>
</button>
{/if}
</div> </div>
</div> </div>

File diff suppressed because one or more lines are too long

View File

@@ -1,24 +0,0 @@
<script lang="ts">
interface Props {
class?: string;
size?: string | number;
}
let { class: className = "", size = "24" }: Props = $props();
</script>
<svg
width={size}
height={size}
viewBox="0 0 512 512"
class={className}
xmlns="http://www.w3.org/2000/svg"
>
<g class="" transform="translate(0,0)" style=""
><path
d="M418.813 30.625c-21.178 26.27-49.712 50.982-84.125 70.844-36.778 21.225-75.064 33.62-110.313 38.06a310.317 310.317 0 0 0 6.813 18.25c16.01.277 29.366-.434 36.406-1.5l9.47-1.53 8.436-1.28.22 10.186a307.48 307.48 0 0 1-1.095 18.72l56.625 8.843c.86-.095 1.713-.15 2.563-.157 11.188-.114 21.44 7.29 24.468 18.593.657 2.448.922 4.903.845 7.313 5.972-2.075 11.753-4.305 17.28-6.72l9.595-4.188 2.313 10.22a340.211 340.211 0 0 1 7.375 48.062C438.29 247.836 468.438 225.71 493 197.5c-3.22-36.73-16.154-78.04-39.125-117.813a290.509 290.509 0 0 0-2.22-3.78l-27.56 71.374c5.154.762 10.123 3.158 14.092 7.126 9.81 9.807 9.813 25.69 0 35.5-9.812 9.81-25.722 9.807-35.53 0-8.86-8.858-9.69-22.68-2.532-32.5l38.938-100.844a322.02 322.02 0 0 0-20.25-25.937zM51.842 118.72c-8.46 17.373-15.76 36.198-21.187 56.436-14.108 52.617-13.96 103.682-2.812 143.438 13.3-2.605 26.442-3.96 39.312-4.03 1.855-.012 3.688.02 5.53.06 20.857.48 40.98 4.332 59.97 11.5a355.064 355.064 0 0 1-1.656-34.218c0-27.8 3.135-54.377 9-78.937l2.47-10.407 9.655 4.562c29.467 13.98 66.194 23.424 106.28 25.22 5.136-20.05 8.19-39.78 9.408-58.75-35.198 4.83-75.387 2.766-116.407-8.22-38.363-10.272-72.314-26.78-99.562-46.656zm230.594 82.218c-1.535 10.452-3.615 21.03-6.218 31.687a312.754 312.754 0 0 0 46-3.97 24.98 24.98 0 0 1-1.532-21.748l-38.25-5.97zM105 201.375l4.156 18.22-21.594 4.905c8.75 5.174 13.353 15.703 10.594 26-3.32 12.394-16.045 19.758-28.437 16.438-12.394-3.32-19.76-16.075-16.44-28.47a23.235 23.235 0 0 1 3.126-6.874l-21.062 4.78-4.125-18.218 73.78-16.78zm388.594 22.813c-25.53 25.46-55.306 45.445-86.906 60.5.05 2.397.093 4.8.093 7.218 0 9.188-.354 18.232-1.03 27.125 16.635 1.33 32.045-1.7 45.344-9.374 25.925-14.962 40.608-45.694 42.5-85.47zm-338.844 3c-4.03 19.993-6.33 41.31-6.406 63.593l.125-.342c30.568 10.174 62.622 17.572 95.25 21.375l7.5.875.718 7.5 5.687 60.125-18.625 1.75-2.53-26.75a23.117 23.117 0 0 1-14.845.968c-12.393-3.32-19.76-16.042-16.438-28.436.285-1.06.647-2.08 1.063-3.063a496.627 496.627 0 0 1-57.406-14.53c2.69 49.62 16.154 94.04 36.094 126.656 22.366 36.588 52.13 57.78 83.968 57.78 31.838.003 61.602-21.19 83.97-57.78 19.536-31.96 32.846-75.244 35.905-123.656a499.132 499.132 0 0 1-48.25 11.656c1.914 4.57 2.415 9.78 1.033 14.938-3.322 12.394-16.045 19.758-28.438 16.437a23.01 23.01 0 0 1-2.125-.686l-2.5 26.47-18.594-1.752 5.688-60.125.72-7.5 7.498-.875c29.245-3.407 57.995-9.717 85.657-18.312v-1.594c0-21.573-2.27-42.23-6.064-61.75C351.132 242.653 313.092 250 272.312 250c-43.59 0-83.986-8.658-117.562-22.813zm-87.5 105.968c-10.87.102-21.995 1.22-33.375 3.313 12.695 31.62 33.117 53.07 59 60 16.9 4.523 34.896 2.536 52.813-5.25-4.382-13.89-7.874-28.606-10.344-43.97-21.115-9.623-43.934-14.32-68.094-14.094zm137.5 80.22h130.813c-40.082 44.594-92.623 42.844-130.813 0z"
fill-opacity="1"
style="fill: currentColor; stroke: #ce47eb; stroke-width: 10px;"
></path></g
></svg
>

View File

@@ -145,7 +145,12 @@
{#if isViewerOpen} {#if isViewerOpen}
<div class="fixed inset-0 z-50 flex items-center justify-center animate-fade-in"> <div class="fixed inset-0 z-50 flex items-center justify-center animate-fade-in">
<!-- Backdrop --> <!-- Backdrop -->
<div class="absolute inset-0 bg-black/95 backdrop-blur-xl" onclick={closeViewer}></div> <button
type="button"
class="absolute inset-0 bg-black/95 backdrop-blur-xl cursor-default"
onclick={closeViewer}
aria-label="Close viewer"
></button>
<!-- Viewer Content --> <!-- Viewer Content -->
<div class="relative w-[90vw] h-[90vh] flex flex-col animate-slide-up"> <div class="relative w-[90vw] h-[90vh] flex flex-col animate-slide-up">

View File

@@ -1,21 +1,5 @@
<script lang="ts"> <script lang="ts">
import { _ } from "svelte-i18n"; import SexyIcon from "../icon/icon.svelte";
import PeonyIcon from "../icon/peony-icon.svelte";
const { hideName = false } = $props();
</script> </script>
<div class="relative"> <SexyIcon class="w-12 h-12" />
<PeonyIcon class="w-13 h-13 text-black" />
</div>
<span
class={`logo text-3xl text-foreground opacity-90 tracking-wide font-extrabold drop-shadow-x ${hideName ? "hidden sm:inline-block" : ""}`}
>
{$_("brand.name")}
</span>
<style>
.logo {
font-family: "Dancing Script", cursive;
}
</style>

View File

@@ -11,15 +11,17 @@
interface Props { interface Props {
user: User; user: User;
onLogout: () => void; onLogout: () => void;
class?: string;
} }
let { user, onLogout }: Props = $props(); let { user, onLogout, class: className = "" }: Props = $props();
let container: HTMLDivElement;
let isDragging = $state(false); let isDragging = $state(false);
let slidePosition = $state(0); let slidePosition = $state(0);
let startX = 0; let startX = 0;
let currentX = 0; let currentX = 0;
let maxSlide = 117; // Maximum slide distance let maxSlide = $derived(container ? container.offsetWidth - 40 : 117);
let threshold = 0.75; // 70% threshold to trigger logout let threshold = 0.75; // 70% threshold to trigger logout
// Calculate slide progress (0 to 1) // Calculate slide progress (0 to 1)
@@ -102,9 +104,10 @@
</script> </script>
<div <div
bind:this={container}
class="relative h-10 w-40 rounded-full bg-muted/30 overflow-hidden select-none transition-all duration-300 bg-muted/40 shadow-lg shadow-accent/10 {isDragging class="relative h-10 w-40 rounded-full bg-muted/30 overflow-hidden select-none transition-all duration-300 bg-muted/40 shadow-lg shadow-accent/10 {isDragging
? 'cursor-grabbing' ? 'cursor-grabbing'
: ''}" : ''} {className}"
style="background: linear-gradient(90deg, style="background: linear-gradient(90deg,
oklch(var(--primary) / 0.3) 0%, oklch(var(--primary) / 0.3) 0%,
oklch(var(--primary) / 0.3) {(1 - slideProgress) * 100}%, oklch(var(--primary) / 0.3) {(1 - slideProgress) * 100}%,

View File

@@ -0,0 +1,33 @@
<script lang="ts">
import type { Snippet } from "svelte";
interface Props {
title: string;
description?: string;
children?: Snippet;
}
let { title, description, children }: Props = $props();
</script>
<section class="relative py-12 md:py-20 overflow-hidden">
<div class="relative container mx-auto px-4 text-center">
<div class="max-w-5xl mx-auto">
<h1
class="text-5xl md:text-7xl font-bold mb-6 bg-gradient-to-r from-primary via-accent to-primary bg-clip-text text-transparent"
>
{title}
</h1>
{#if description}
<p
class="text-xl md:text-2xl text-muted-foreground mb-10 leading-relaxed max-w-4xl mx-auto"
>
{description}
</p>
{/if}
{#if children}
{@render children()}
{/if}
</div>
</div>
</section>

View File

@@ -0,0 +1,63 @@
<script lang="ts">
import { Button } from "$lib/components/ui/button";
import { _ } from "svelte-i18n";
interface Props {
currentPage: number;
totalPages: number;
onPageChange: (page: number) => void;
}
let { currentPage, totalPages, onPageChange }: Props = $props();
const pageNumbers = $derived(() => {
const pages: (number | -1)[] = [];
if (totalPages <= 7) {
for (let i = 1; i <= totalPages; i++) pages.push(i);
} else {
pages.push(1);
if (currentPage > 3) pages.push(-1);
for (
let i = Math.max(2, currentPage - 1);
i <= Math.min(totalPages - 1, currentPage + 1);
i++
)
pages.push(i);
if (currentPage < totalPages - 2) pages.push(-1);
pages.push(totalPages);
}
return pages;
});
</script>
{#if totalPages > 1}
<div class="flex items-center gap-1">
<Button
variant="outline"
disabled={currentPage <= 1}
onclick={() => onPageChange(currentPage - 1)}
>
{$_("common.previous")}
</Button>
{#each pageNumbers() as p, i (i)}
{#if p === -1}
<span class="px-2 text-muted-foreground select-none"></span>
{:else}
<Button
variant={p === currentPage ? "default" : "outline"}
class="min-w-9"
onclick={() => onPageChange(p)}
>
{p}
</Button>
{/if}
{/each}
<Button
variant="outline"
disabled={currentPage >= totalPages}
onclick={() => onPageChange(currentPage + 1)}
>
{$_("common.next")}
</Button>
</div>
{/if}

View File

@@ -2,16 +2,18 @@
import { _ } from "svelte-i18n"; import { _ } from "svelte-i18n";
import { Card, CardContent, CardHeader } from "$lib/components/ui/card"; import { Card, CardContent, CardHeader } from "$lib/components/ui/card";
import { Button } from "$lib/components/ui/button"; import { Button } from "$lib/components/ui/button";
import { Badge } from "$lib/components/ui/badge";
import type { Recording, DeviceInfo } from "$lib/types"; import type { Recording, DeviceInfo } from "$lib/types";
import { cn } from "$lib/utils";
interface Props { interface Props {
recording: Recording; recording: Recording;
onPlay?: (id: string) => void; onPlay?: (id: string) => void;
onPublish?: (id: string) => void;
onUnpublish?: (id: string) => void;
onDelete?: (id: string) => void; onDelete?: (id: string) => void;
} }
let { recording, onPlay, onDelete }: Props = $props(); let { recording, onPlay, onPublish, onUnpublish, onDelete }: Props = $props();
function formatDuration(ms: number): string { function formatDuration(ms: number): string {
const totalSeconds = Math.floor(ms / 1000); const totalSeconds = Math.floor(ms / 1000);
@@ -19,19 +21,6 @@
const seconds = totalSeconds % 60; const seconds = totalSeconds % 60;
return `${minutes}:${seconds.toString().padStart(2, "0")}`; return `${minutes}:${seconds.toString().padStart(2, "0")}`;
} }
function getStatusColor(status: string): string {
switch (status) {
case "published":
return "text-green-400 bg-green-400/20";
case "draft":
return "text-yellow-400 bg-yellow-400/20";
case "archived":
return "text-red-400 bg-red-400/20";
default:
return "text-gray-400 bg-gray-400/20";
}
}
</script> </script>
<Card <Card
@@ -44,9 +33,14 @@
<h3 class="font-semibold text-card-foreground group-hover:text-primary transition-colors"> <h3 class="font-semibold text-card-foreground group-hover:text-primary transition-colors">
{recording.title} {recording.title}
</h3> </h3>
<span class={cn("text-xs px-2 py-0.5 rounded-full", getStatusColor(recording.status))}> <Badge
variant="outline"
class={recording.status === "published"
? "text-green-600 border-green-500/40 bg-green-500/10"
: "text-yellow-600 border-yellow-500/40 bg-yellow-500/10"}
>
{$_(`recording_card.status_${recording.status}`)} {$_(`recording_card.status_${recording.status}`)}
</span> </Badge>
</div> </div>
{#if recording.description} {#if recording.description}
<p class="text-sm text-muted-foreground line-clamp-2"> <p class="text-sm text-muted-foreground line-clamp-2">
@@ -151,12 +145,35 @@
{$_("recording_card.play")} {$_("recording_card.play")}
</Button> </Button>
{/if} {/if}
{#if onPublish && recording.status === "draft"}
<Button
size="sm"
variant="outline"
onclick={() => onPublish?.(recording.id)}
class="cursor-pointer border-primary/20 hover:bg-primary/10 hover:text-primary"
title={$_("recording_card.publish")}
>
<span class="icon-[ri--send-plane-line] w-4 h-4"></span>
</Button>
{/if}
{#if onUnpublish && recording.status === "published"}
<Button
size="sm"
variant="outline"
onclick={() => onUnpublish?.(recording.id)}
class="cursor-pointer border-muted-foreground/20 hover:bg-muted/50 hover:text-muted-foreground"
title={$_("recording_card.unpublish")}
>
<span class="icon-[ri--arrow-go-back-line] w-4 h-4"></span>
</Button>
{/if}
{#if onDelete} {#if onDelete}
<Button <Button
size="sm" size="sm"
variant="outline" variant="outline"
onclick={() => onDelete?.(recording.id)} onclick={() => onDelete?.(recording.id)}
class="cursor-pointer border-destructive/20 hover:bg-destructive/10 hover:text-destructive" class="cursor-pointer border-destructive/20 hover:bg-destructive/10 hover:text-destructive"
title={$_("common.delete")}
> >
<span class="icon-[ri--delete-bin-line] w-4 h-4"></span> <span class="icon-[ri--delete-bin-line] w-4 h-4"></span>
</Button> </Button>

View File

@@ -0,0 +1,49 @@
<script lang="ts" module>
import { type VariantProps, tv } from "tailwind-variants";
export const badgeVariants = tv({
base: "focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] [&>svg]:pointer-events-none [&>svg]:size-3",
variants: {
variant: {
default: "bg-primary text-primary-foreground [a&]:hover:bg-primary/90 border-transparent",
secondary:
"bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90 border-transparent",
destructive:
"bg-destructive [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/70 border-transparent text-white",
outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
},
},
defaultVariants: {
variant: "default",
},
});
export type BadgeVariant = VariantProps<typeof badgeVariants>["variant"];
</script>
<script lang="ts">
import type { HTMLAnchorAttributes } from "svelte/elements";
import { cn, type WithElementRef } from "$lib/utils.js";
let {
ref = $bindable(null),
href,
class: className,
variant = "default",
children,
...restProps
}: WithElementRef<HTMLAnchorAttributes> & {
variant?: BadgeVariant;
} = $props();
</script>
<svelte:element
this={href ? "a" : "span"}
bind:this={ref}
data-slot="badge"
{href}
class={cn(badgeVariants({ variant }), className)}
{...restProps}
>
{@render children?.()}
</svelte:element>

View File

@@ -0,0 +1,2 @@
export { default as Badge } from "./badge.svelte";
export { badgeVariants, type BadgeVariant } from "./badge.svelte";

View File

@@ -0,0 +1,76 @@
<script lang="ts">
import type { ComponentProps } from "svelte";
import type Calendar from "./calendar.svelte";
import CalendarMonthSelect from "./calendar-month-select.svelte";
import CalendarYearSelect from "./calendar-year-select.svelte";
import { DateFormatter, getLocalTimeZone, type DateValue } from "@internationalized/date";
let {
captionLayout,
months,
monthFormat,
years,
yearFormat,
month,
locale,
placeholder = $bindable(),
monthIndex = 0,
}: {
captionLayout: ComponentProps<typeof Calendar>["captionLayout"];
months: ComponentProps<typeof CalendarMonthSelect>["months"];
monthFormat: ComponentProps<typeof CalendarMonthSelect>["monthFormat"];
years: ComponentProps<typeof CalendarYearSelect>["years"];
yearFormat: ComponentProps<typeof CalendarYearSelect>["yearFormat"];
month: DateValue;
placeholder: DateValue | undefined;
locale: string;
monthIndex: number;
} = $props();
function formatYear(date: DateValue) {
const dateObj = date.toDate(getLocalTimeZone());
if (typeof yearFormat === "function") return yearFormat(dateObj.getFullYear());
return new DateFormatter(locale, { year: yearFormat }).format(dateObj);
}
function formatMonth(date: DateValue) {
const dateObj = date.toDate(getLocalTimeZone());
if (typeof monthFormat === "function") return monthFormat(dateObj.getMonth() + 1);
return new DateFormatter(locale, { month: monthFormat }).format(dateObj);
}
</script>
{#snippet MonthSelect()}
<CalendarMonthSelect
{months}
{monthFormat}
value={month.month}
onchange={(e) => {
if (!placeholder) return;
const v = Number.parseInt(e.currentTarget.value);
const newPlaceholder = placeholder.set({ month: v });
placeholder = newPlaceholder.subtract({ months: monthIndex });
}}
/>
{/snippet}
{#snippet YearSelect()}
<CalendarYearSelect {years} {yearFormat} value={month.year} />
{/snippet}
{#if captionLayout === "dropdown"}
{@render MonthSelect()}
{@render YearSelect()}
{:else if captionLayout === "dropdown-months"}
{@render MonthSelect()}
{#if placeholder}
{formatYear(placeholder)}
{/if}
{:else if captionLayout === "dropdown-years"}
{#if placeholder}
{formatMonth(placeholder)}
{/if}
{@render YearSelect()}
{:else}
{formatMonth(month)} {formatYear(month)}
{/if}

View File

@@ -0,0 +1,19 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import { cn } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
...restProps
}: CalendarPrimitive.CellProps = $props();
</script>
<CalendarPrimitive.Cell
bind:ref
class={cn(
"relative size-(--cell-size) p-0 text-center text-sm focus-within:z-20 [&:first-child[data-selected]_[data-bits-day]]:rounded-s-md [&:last-child[data-selected]_[data-bits-day]]:rounded-e-md",
className,
)}
{...restProps}
/>

View File

@@ -0,0 +1,35 @@
<script lang="ts">
import { buttonVariants } from "$lib/components/ui/button/index.js";
import { cn } from "$lib/utils.js";
import { Calendar as CalendarPrimitive } from "bits-ui";
let {
ref = $bindable(null),
class: className,
...restProps
}: CalendarPrimitive.DayProps = $props();
</script>
<CalendarPrimitive.Day
bind:ref
class={cn(
buttonVariants({ variant: "ghost" }),
"flex size-(--cell-size) flex-col items-center justify-center gap-1 p-0 leading-none font-normal whitespace-nowrap select-none",
"[&[data-today]:not([data-selected])]:bg-accent [&[data-today]:not([data-selected])]:text-accent-foreground [&[data-today][data-disabled]]:text-muted-foreground",
"data-[selected]:bg-primary dark:data-[selected]:hover:bg-accent/50 data-[selected]:text-primary-foreground",
// Outside months
"[&[data-outside-month]:not([data-selected])]:text-muted-foreground [&[data-outside-month]:not([data-selected])]:hover:text-accent-foreground",
// Disabled
"data-[disabled]:text-muted-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
// Unavailable
"data-[unavailable]:text-muted-foreground data-[unavailable]:line-through",
// hover
"dark:hover:text-accent-foreground",
// focus
"focus:border-ring focus:ring-ring/50 focus:relative",
// inner spans
"[&>span]:text-xs [&>span]:opacity-70",
className,
)}
{...restProps}
/>

View File

@@ -0,0 +1,12 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import { cn } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
...restProps
}: CalendarPrimitive.GridBodyProps = $props();
</script>
<CalendarPrimitive.GridBody bind:ref class={cn(className)} {...restProps} />

View File

@@ -0,0 +1,12 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import { cn } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
...restProps
}: CalendarPrimitive.GridHeadProps = $props();
</script>
<CalendarPrimitive.GridHead bind:ref class={cn(className)} {...restProps} />

View File

@@ -0,0 +1,12 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import { cn } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
...restProps
}: CalendarPrimitive.GridRowProps = $props();
</script>
<CalendarPrimitive.GridRow bind:ref class={cn("flex", className)} {...restProps} />

View File

@@ -0,0 +1,16 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import { cn } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
...restProps
}: CalendarPrimitive.GridProps = $props();
</script>
<CalendarPrimitive.Grid
bind:ref
class={cn("mt-4 flex w-full border-collapse flex-col gap-1", className)}
{...restProps}
/>

View File

@@ -0,0 +1,19 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import { cn } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
...restProps
}: CalendarPrimitive.HeadCellProps = $props();
</script>
<CalendarPrimitive.HeadCell
bind:ref
class={cn(
"text-muted-foreground w-(--cell-size) rounded-md text-[0.8rem] font-normal",
className,
)}
{...restProps}
/>

View File

@@ -0,0 +1,19 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import { cn } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
...restProps
}: CalendarPrimitive.HeaderProps = $props();
</script>
<CalendarPrimitive.Header
bind:ref
class={cn(
"flex h-(--cell-size) w-full items-center justify-center gap-1.5 text-sm font-medium",
className,
)}
{...restProps}
/>

View File

@@ -0,0 +1,16 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import { cn } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
...restProps
}: CalendarPrimitive.HeadingProps = $props();
</script>
<CalendarPrimitive.Heading
bind:ref
class={cn("px-(--cell-size) text-sm font-medium", className)}
{...restProps}
/>

View File

@@ -0,0 +1,48 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import { cn, type WithoutChildrenOrChild } from "$lib/utils.js";
import ChevronDownIcon from "@lucide/svelte/icons/chevron-down";
let {
ref = $bindable(null),
class: className,
value,
onchange,
...restProps
}: WithoutChildrenOrChild<CalendarPrimitive.MonthSelectProps> = $props();
</script>
<span
class={cn(
"has-focus:border-ring border-input has-focus:ring-ring/50 relative flex rounded-md border shadow-xs has-focus:ring-[3px]",
className,
)}
>
<CalendarPrimitive.MonthSelect
bind:ref
class="dark:bg-popover dark:text-popover-foreground absolute inset-0 opacity-0"
{...restProps}
>
{#snippet child({ props, monthItems, selectedMonthItem })}
<select {...props} {value} {onchange}>
{#each monthItems as monthItem (monthItem.value)}
<option
value={monthItem.value}
selected={value !== undefined
? monthItem.value === value
: monthItem.value === selectedMonthItem.value}
>
{monthItem.label}
</option>
{/each}
</select>
<span
class="[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md ps-2 pe-1 text-sm font-medium select-none [&>svg]:size-3.5"
aria-hidden="true"
>
{monthItems.find((item) => item.value === value)?.label || selectedMonthItem.label}
<ChevronDownIcon class="size-4" />
</span>
{/snippet}
</CalendarPrimitive.MonthSelect>
</span>

View File

@@ -0,0 +1,15 @@
<script lang="ts">
import { type WithElementRef, cn } from "$lib/utils.js";
import type { HTMLAttributes } from "svelte/elements";
let {
ref = $bindable(null),
class: className,
children,
...restProps
}: WithElementRef<HTMLAttributes<HTMLElement>> = $props();
</script>
<div {...restProps} bind:this={ref} class={cn("flex flex-col", className)}>
{@render children?.()}
</div>

View File

@@ -0,0 +1,19 @@
<script lang="ts">
import type { HTMLAttributes } from "svelte/elements";
import { cn, type WithElementRef } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
children,
...restProps
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
</script>
<div
bind:this={ref}
class={cn("relative flex flex-col gap-4 md:flex-row", className)}
{...restProps}
>
{@render children?.()}
</div>

View File

@@ -0,0 +1,19 @@
<script lang="ts">
import { cn, type WithElementRef } from "$lib/utils.js";
import type { HTMLAttributes } from "svelte/elements";
let {
ref = $bindable(null),
class: className,
children,
...restProps
}: WithElementRef<HTMLAttributes<HTMLElement>> = $props();
</script>
<nav
{...restProps}
bind:this={ref}
class={cn("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1", className)}
>
{@render children?.()}
</nav>

View File

@@ -0,0 +1,31 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import ChevronRightIcon from "@lucide/svelte/icons/chevron-right";
import { buttonVariants, type ButtonVariant } from "$lib/components/ui/button/index.js";
import { cn } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
children,
variant = "ghost",
...restProps
}: CalendarPrimitive.NextButtonProps & {
variant?: ButtonVariant;
} = $props();
</script>
{#snippet Fallback()}
<ChevronRightIcon class="size-4" />
{/snippet}
<CalendarPrimitive.NextButton
bind:ref
class={cn(
buttonVariants({ variant }),
"size-(--cell-size) bg-transparent p-0 select-none disabled:opacity-50 rtl:rotate-180",
className,
)}
children={children || Fallback}
{...restProps}
/>

View File

@@ -0,0 +1,31 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import ChevronLeftIcon from "@lucide/svelte/icons/chevron-left";
import { buttonVariants, type ButtonVariant } from "$lib/components/ui/button/index.js";
import { cn } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
children,
variant = "ghost",
...restProps
}: CalendarPrimitive.PrevButtonProps & {
variant?: ButtonVariant;
} = $props();
</script>
{#snippet Fallback()}
<ChevronLeftIcon class="size-4" />
{/snippet}
<CalendarPrimitive.PrevButton
bind:ref
class={cn(
buttonVariants({ variant }),
"size-(--cell-size) bg-transparent p-0 select-none disabled:opacity-50 rtl:rotate-180",
className,
)}
children={children || Fallback}
{...restProps}
/>

View File

@@ -0,0 +1,47 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import { cn, type WithoutChildrenOrChild } from "$lib/utils.js";
import ChevronDownIcon from "@lucide/svelte/icons/chevron-down";
let {
ref = $bindable(null),
class: className,
value,
...restProps
}: WithoutChildrenOrChild<CalendarPrimitive.YearSelectProps> = $props();
</script>
<span
class={cn(
"has-focus:border-ring border-input has-focus:ring-ring/50 relative flex rounded-md border shadow-xs has-focus:ring-[3px]",
className,
)}
>
<CalendarPrimitive.YearSelect
bind:ref
class="dark:bg-popover dark:text-popover-foreground absolute inset-0 opacity-0"
{...restProps}
>
{#snippet child({ props, yearItems, selectedYearItem })}
<select {...props} {value}>
{#each yearItems as yearItem (yearItem.value)}
<option
value={yearItem.value}
selected={value !== undefined
? yearItem.value === value
: yearItem.value === selectedYearItem.value}
>
{yearItem.label}
</option>
{/each}
</select>
<span
class="[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md ps-2 pe-1 text-sm font-medium select-none [&>svg]:size-3.5"
aria-hidden="true"
>
{yearItems.find((item) => item.value === value)?.label || selectedYearItem.label}
<ChevronDownIcon class="size-4" />
</span>
{/snippet}
</CalendarPrimitive.YearSelect>
</span>

View File

@@ -0,0 +1,115 @@
<script lang="ts">
import { Calendar as CalendarPrimitive } from "bits-ui";
import * as Calendar from "./index.js";
import { cn, type WithoutChildrenOrChild } from "$lib/utils.js";
import type { ButtonVariant } from "../button/button.svelte";
import { isEqualMonth, type DateValue } from "@internationalized/date";
import type { Snippet } from "svelte";
let {
ref = $bindable(null),
value = $bindable(),
placeholder = $bindable(),
class: className,
weekdayFormat = "short",
buttonVariant = "ghost",
captionLayout = "label",
locale = "en-US",
months: monthsProp,
years,
monthFormat: monthFormatProp,
yearFormat = "numeric",
day,
disableDaysOutsideMonth = false,
...restProps
}: WithoutChildrenOrChild<CalendarPrimitive.RootProps> & {
buttonVariant?: ButtonVariant;
captionLayout?: "dropdown" | "dropdown-months" | "dropdown-years" | "label";
months?: CalendarPrimitive.MonthSelectProps["months"];
years?: CalendarPrimitive.YearSelectProps["years"];
monthFormat?: CalendarPrimitive.MonthSelectProps["monthFormat"];
yearFormat?: CalendarPrimitive.YearSelectProps["yearFormat"];
day?: Snippet<[{ day: DateValue; outsideMonth: boolean }]>;
} = $props();
const monthFormat = $derived.by(() => {
if (monthFormatProp) return monthFormatProp;
if (captionLayout.startsWith("dropdown")) return "short";
return "long";
});
</script>
<!--
Discriminated Unions + Destructing (required for bindable) do not
get along, so we shut typescript up by casting `value` to `never`.
-->
<CalendarPrimitive.Root
bind:value={value as never}
bind:ref
bind:placeholder
{weekdayFormat}
{disableDaysOutsideMonth}
class={cn(
"bg-background group/calendar p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",
className,
)}
{locale}
{monthFormat}
{yearFormat}
{...restProps}
>
{#snippet children({ months, weekdays })}
<Calendar.Months>
<Calendar.Nav>
<Calendar.PrevButton variant={buttonVariant} />
<Calendar.NextButton variant={buttonVariant} />
</Calendar.Nav>
{#each months as month, monthIndex (month)}
<Calendar.Month>
<Calendar.Header>
<Calendar.Caption
{captionLayout}
months={monthsProp}
{monthFormat}
{years}
{yearFormat}
month={month.value}
bind:placeholder
{locale}
{monthIndex}
/>
</Calendar.Header>
<Calendar.Grid>
<Calendar.GridHead>
<Calendar.GridRow class="select-none">
{#each weekdays as weekday (weekday)}
<Calendar.HeadCell>
{weekday.slice(0, 2)}
</Calendar.HeadCell>
{/each}
</Calendar.GridRow>
</Calendar.GridHead>
<Calendar.GridBody>
{#each month.weeks as weekDates (weekDates)}
<Calendar.GridRow class="mt-2 w-full">
{#each weekDates as date (date)}
<Calendar.Cell {date} month={month.value}>
{#if day}
{@render day({
day: date,
outsideMonth: !isEqualMonth(date, month.value),
})}
{:else}
<Calendar.Day />
{/if}
</Calendar.Cell>
{/each}
</Calendar.GridRow>
{/each}
</Calendar.GridBody>
</Calendar.Grid>
</Calendar.Month>
{/each}
</Calendar.Months>
{/snippet}
</CalendarPrimitive.Root>

View File

@@ -0,0 +1,40 @@
import Root from "./calendar.svelte";
import Cell from "./calendar-cell.svelte";
import Day from "./calendar-day.svelte";
import Grid from "./calendar-grid.svelte";
import Header from "./calendar-header.svelte";
import Months from "./calendar-months.svelte";
import GridRow from "./calendar-grid-row.svelte";
import Heading from "./calendar-heading.svelte";
import GridBody from "./calendar-grid-body.svelte";
import GridHead from "./calendar-grid-head.svelte";
import HeadCell from "./calendar-head-cell.svelte";
import NextButton from "./calendar-next-button.svelte";
import PrevButton from "./calendar-prev-button.svelte";
import MonthSelect from "./calendar-month-select.svelte";
import YearSelect from "./calendar-year-select.svelte";
import Month from "./calendar-month.svelte";
import Nav from "./calendar-nav.svelte";
import Caption from "./calendar-caption.svelte";
export {
Day,
Cell,
Grid,
Header,
Months,
GridRow,
Heading,
GridBody,
GridHead,
HeadCell,
NextButton,
PrevButton,
Nav,
Month,
YearSelect,
MonthSelect,
Caption,
//
Root as Calendar,
};

View File

@@ -0,0 +1,85 @@
<script lang="ts">
import { parseDate, type DateValue } from "@internationalized/date";
import { Calendar } from "$lib/components/ui/calendar";
import * as Popover from "$lib/components/ui/popover";
import { Button } from "$lib/components/ui/button";
let {
value = $bindable(""),
placeholder = "Pick a date",
showTime = true,
}: {
value?: string;
placeholder?: string;
showTime?: boolean;
} = $props();
function toCalendarDate(v: string): DateValue | undefined {
if (!v) return undefined;
try {
return parseDate(v.slice(0, 10));
} catch {
return undefined;
}
}
function pad(n: number) {
return String(n).padStart(2, "0");
}
let calendarDate = $state<DateValue | undefined>(toCalendarDate(value));
let timeStr = $state(value.length >= 16 ? value.slice(11, 16) : "00:00");
let open = $state(false);
$effect(() => {
if (calendarDate) {
const d = calendarDate;
const dateStr = `${d.year}-${pad(d.month)}-${pad(d.day)}`;
value = showTime ? `${dateStr}T${timeStr}` : dateStr;
} else {
value = "";
}
});
let displayLabel = $derived.by(() => {
if (!calendarDate) return placeholder;
const d = calendarDate;
const date = new Date(d.year, d.month - 1, d.day);
const dateLabel = date.toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
});
return showTime ? `${dateLabel} ${timeStr}` : dateLabel;
});
</script>
<Popover.Root bind:open>
<Popover.Trigger>
{#snippet child({ props })}
<Button
variant="outline"
{...props}
class="w-full justify-start font-normal {!calendarDate ? 'text-muted-foreground' : ''}"
>
<span class="icon-[ri--calendar-line] h-4 w-4 mr-2 shrink-0"></span>
{displayLabel}
</Button>
{/snippet}
</Popover.Trigger>
<Popover.Content class="w-auto p-0" align="start">
<Calendar bind:value={calendarDate} />
{#if showTime}
<div class="border-t border-border/40 p-3">
<input
type="time"
value={timeStr}
oninput={(e) => {
timeStr = (e.target as HTMLInputElement).value;
}}
class="w-full rounded-md border border-input bg-background px-3 py-1.5 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
/>
</div>
{/if}
</Popover.Content>
</Popover.Root>

View File

@@ -0,0 +1 @@
export { default as DatePicker } from "./date-picker.svelte";

View File

@@ -0,0 +1,23 @@
<script lang="ts">
import { cn, type WithElementRef } from "$lib/utils.js";
import type { HTMLAttributes } from "svelte/elements";
let {
ref = $bindable(null),
class: className,
children,
...restProps
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
</script>
<div
bind:this={ref}
data-slot="empty-content"
class={cn(
"flex w-full max-w-sm min-w-0 flex-col items-center gap-4 text-sm text-balance",
className,
)}
{...restProps}
>
{@render children?.()}
</div>

View File

@@ -0,0 +1,23 @@
<script lang="ts">
import { cn, type WithElementRef } from "$lib/utils.js";
import type { HTMLAttributes } from "svelte/elements";
let {
ref = $bindable(null),
class: className,
children,
...restProps
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
</script>
<div
bind:this={ref}
data-slot="empty-description"
class={cn(
"text-muted-foreground [&>a:hover]:text-primary text-sm/relaxed [&>a]:underline [&>a]:underline-offset-4",
className,
)}
{...restProps}
>
{@render children?.()}
</div>

View File

@@ -0,0 +1,20 @@
<script lang="ts">
import { cn, type WithElementRef } from "$lib/utils.js";
import type { HTMLAttributes } from "svelte/elements";
let {
ref = $bindable(null),
class: className,
children,
...restProps
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
</script>
<div
bind:this={ref}
data-slot="empty-header"
class={cn("flex max-w-sm flex-col items-center gap-2 text-center", className)}
{...restProps}
>
{@render children?.()}
</div>

View File

@@ -0,0 +1,41 @@
<script lang="ts" module>
import { tv, type VariantProps } from "tailwind-variants";
export const emptyMediaVariants = tv({
base: "mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
variants: {
variant: {
default: "bg-transparent",
icon: "bg-muted text-foreground flex size-10 shrink-0 items-center justify-center rounded-lg [&_svg:not([class*='size-'])]:size-6",
},
},
defaultVariants: {
variant: "default",
},
});
export type EmptyMediaVariant = VariantProps<typeof emptyMediaVariants>["variant"];
</script>
<script lang="ts">
import { cn, type WithElementRef } from "$lib/utils.js";
import type { HTMLAttributes } from "svelte/elements";
let {
ref = $bindable(null),
class: className,
children,
variant = "default",
...restProps
}: WithElementRef<HTMLAttributes<HTMLDivElement>> & { variant?: EmptyMediaVariant } = $props();
</script>
<div
bind:this={ref}
data-slot="empty-icon"
data-variant={variant}
class={cn(emptyMediaVariants({ variant }), className)}
{...restProps}
>
{@render children?.()}
</div>

View File

@@ -0,0 +1,20 @@
<script lang="ts">
import { cn, type WithElementRef } from "$lib/utils.js";
import type { HTMLAttributes } from "svelte/elements";
let {
ref = $bindable(null),
class: className,
children,
...restProps
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
</script>
<div
bind:this={ref}
data-slot="empty-title"
class={cn("text-lg font-medium tracking-tight", className)}
{...restProps}
>
{@render children?.()}
</div>

View File

@@ -0,0 +1,23 @@
<script lang="ts">
import { cn, type WithElementRef } from "$lib/utils.js";
import type { HTMLAttributes } from "svelte/elements";
let {
ref = $bindable(null),
class: className,
children,
...restProps
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
</script>
<div
bind:this={ref}
data-slot="empty"
class={cn(
"flex min-w-0 flex-1 flex-col items-center justify-center gap-6 rounded-lg border-dashed p-6 text-center text-balance md:p-12",
className,
)}
{...restProps}
>
{@render children?.()}
</div>

Some files were not shown because too many files have changed in this diff Show More