@meith/web 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +165 -0
- package/app/(auth)/layout.tsx +6 -0
- package/app/(auth)/login/page.tsx +106 -0
- package/app/(auth)/login/verify/page.tsx +55 -0
- package/app/(auth)/register/page.tsx +83 -0
- package/app/(auth)/reset/confirm/page.tsx +45 -0
- package/app/(auth)/reset/page.tsx +22 -0
- package/app/(auth)/verify/page.tsx +44 -0
- package/app/(auth)/verify/resend/page.tsx +51 -0
- package/app/(board)/[slug]/feed.xml/route.ts +48 -0
- package/app/(board)/[slug]/new/page.tsx +112 -0
- package/app/(board)/[slug]/page.tsx +403 -0
- package/app/(board)/discover/[view]/page.tsx +115 -0
- package/app/(board)/discover/page.tsx +5 -0
- package/app/(board)/layout.tsx +22 -0
- package/app/(board)/member/[id]/page.tsx +187 -0
- package/app/(board)/member/[id]/reputation/page.tsx +195 -0
- package/app/(board)/member/by-name/[name]/page.tsx +32 -0
- package/app/(board)/messages/[id]/page.tsx +103 -0
- package/app/(board)/messages/compose/page.tsx +60 -0
- package/app/(board)/messages/layout.tsx +5 -0
- package/app/(board)/messages/page.tsx +179 -0
- package/app/(board)/modcp/forums/page.tsx +59 -0
- package/app/(board)/modcp/ip/page.tsx +158 -0
- package/app/(board)/modcp/layout.tsx +5 -0
- package/app/(board)/modcp/log/page.tsx +98 -0
- package/app/(board)/modcp/page.tsx +112 -0
- package/app/(board)/moderation/layout.tsx +5 -0
- package/app/(board)/moderation/page.tsx +111 -0
- package/app/(board)/moderation/reports/page.tsx +193 -0
- package/app/(board)/moderation/warn/page.tsx +158 -0
- package/app/(board)/notifications/layout.tsx +5 -0
- package/app/(board)/notifications/page.tsx +144 -0
- package/app/(board)/notifications/preferences/page.tsx +65 -0
- package/app/(board)/online/page.tsx +119 -0
- package/app/(board)/page.tsx +195 -0
- package/app/(board)/plugins/[key]/[[...path]]/page.tsx +72 -0
- package/app/(board)/privacy/page.tsx +12 -0
- package/app/(board)/report/page.tsx +71 -0
- package/app/(board)/rules/page.tsx +12 -0
- package/app/(board)/search/[token]/page.tsx +130 -0
- package/app/(board)/search/page.tsx +289 -0
- package/app/(board)/stats/page.tsx +202 -0
- package/app/(board)/subscriptions/layout.tsx +5 -0
- package/app/(board)/subscriptions/page.tsx +142 -0
- package/app/(board)/terms/page.tsx +12 -0
- package/app/(board)/thread/[slug]/edit/page.tsx +107 -0
- package/app/(board)/thread/[slug]/feed.xml/route.ts +42 -0
- package/app/(board)/thread/[slug]/page.tsx +707 -0
- package/app/(board)/thread/[slug]/poll/page.tsx +41 -0
- package/app/(board)/thread/[slug]/post/[postId]/history/page.tsx +160 -0
- package/app/(board)/thread/[slug]/reply/page.tsx +136 -0
- package/app/(board)/unsubscribe/page.tsx +73 -0
- package/app/(board)/usercp/avatar/page.tsx +56 -0
- package/app/(board)/usercp/contacts/page.tsx +141 -0
- package/app/(board)/usercp/email/confirm/page.tsx +52 -0
- package/app/(board)/usercp/layout.tsx +23 -0
- package/app/(board)/usercp/options/page.tsx +56 -0
- package/app/(board)/usercp/page.tsx +71 -0
- package/app/(board)/usercp/profile/page.tsx +81 -0
- package/app/(board)/usercp/security/page.tsx +238 -0
- package/app/(board)/usercp/security/verify/page.tsx +92 -0
- package/app/(board)/usercp/signature/page.tsx +67 -0
- package/app/admin/antispam/page.tsx +155 -0
- package/app/admin/api/marketplace/screenshot/route.ts +68 -0
- package/app/admin/api/plugins/[key]/[...path]/route.ts +27 -0
- package/app/admin/api-tokens/page.tsx +129 -0
- package/app/admin/content/announcements/page.tsx +110 -0
- package/app/admin/content/attachments/page.tsx +199 -0
- package/app/admin/content/navigation/page.tsx +123 -0
- package/app/admin/content/page.tsx +170 -0
- package/app/admin/forums/[id]/page.tsx +96 -0
- package/app/admin/forums/[id]/permissions/page.tsx +108 -0
- package/app/admin/forums/page.tsx +45 -0
- package/app/admin/groups/[id]/page.tsx +133 -0
- package/app/admin/groups/memberships/page.tsx +56 -0
- package/app/admin/groups/page.tsx +104 -0
- package/app/admin/groups/promotions/page.tsx +143 -0
- package/app/admin/layout.tsx +86 -0
- package/app/admin/log/page.tsx +116 -0
- package/app/admin/page.tsx +206 -0
- package/app/admin/plugins/[key]/[[...path]]/page.tsx +276 -0
- package/app/admin/plugins/browse/page.tsx +70 -0
- package/app/admin/plugins/page.tsx +165 -0
- package/app/admin/security/page.tsx +124 -0
- package/app/admin/settings/page.tsx +190 -0
- package/app/admin/system/page.tsx +303 -0
- package/app/admin/themes/[key]/page.tsx +110 -0
- package/app/admin/themes/browse/page.tsx +70 -0
- package/app/admin/themes/page.tsx +163 -0
- package/app/admin/users/[id]/merge/page.tsx +136 -0
- package/app/admin/users/[id]/page.tsx +208 -0
- package/app/admin/users/mail/page.tsx +68 -0
- package/app/admin/users/page.tsx +260 -0
- package/app/admin/users/prune/page.tsx +186 -0
- package/app/api/health/route.ts +11 -0
- package/app/api/metrics/route.ts +66 -0
- package/app/api/plugins/[key]/[...path]/route.ts +27 -0
- package/app/api/read/all/route.ts +15 -0
- package/app/api/read/forum/[id]/route.ts +29 -0
- package/app/api/read/thread/[id]/route.ts +40 -0
- package/app/api/ready/route.ts +63 -0
- package/app/api/system/tick/route.ts +77 -0
- package/app/api/v1/[...path]/route.ts +208 -0
- package/app/api/v1/openapi.json/route.ts +12 -0
- package/app/apple-icon.ts +11 -0
- package/app/atom.xml/route.ts +7 -0
- package/app/attachment/[id]/route.ts +10 -0
- package/app/attachment/[id]/thumb/route.ts +10 -0
- package/app/auth/passkey/options/route.ts +145 -0
- package/app/auth/passkey/verify/route.ts +241 -0
- package/app/auth/resume/route.ts +55 -0
- package/app/auth/sso/[provider]/callback/route.ts +173 -0
- package/app/auth/sso/[provider]/go/route.ts +57 -0
- package/app/auth/sso/[provider]/route.ts +105 -0
- package/app/avatar/[id]/route.ts +31 -0
- package/app/brand/icon-192.png/route.ts +7 -0
- package/app/brand/icon-512.png/route.ts +7 -0
- package/app/brand/icon-maskable.png/route.ts +7 -0
- package/app/demo/stripe/[[...path]]/route.ts +27 -0
- package/app/error.tsx +15 -0
- package/app/feed.xml/route.ts +7 -0
- package/app/forumdisplay.php/page.tsx +11 -0
- package/app/group/[id]/badge/[scheme]/route.ts +26 -0
- package/app/icon.ts +13 -0
- package/app/install/page.tsx +221 -0
- package/app/jump/page.tsx +28 -0
- package/app/layout.tsx +124 -0
- package/app/logo/[scheme]/route.ts +24 -0
- package/app/manifest.ts +43 -0
- package/app/member.php/page.tsx +11 -0
- package/app/memberlist.php/page.tsx +11 -0
- package/app/not-found.tsx +14 -0
- package/app/opengraph-image.ts +11 -0
- package/app/redirect/page.tsx +44 -0
- package/app/robots.txt/route.ts +35 -0
- package/app/showthread.php/page.tsx +11 -0
- package/app/sitemap/[page]/route.ts +64 -0
- package/app/sitemap.xml/route.ts +31 -0
- package/app/twitter-image.ts +11 -0
- package/app/viewforum.php/page.tsx +11 -0
- package/app/viewtopic.php/page.tsx +11 -0
- package/bin/forum-web.mjs +241 -0
- package/components.json +21 -0
- package/instrumentation.ts +18 -0
- package/next.config.mjs +182 -0
- package/package.json +99 -0
- package/postcss.config.mjs +7 -0
- package/proxy.ts +160 -0
- package/src/components/account/active-sessions.tsx +87 -0
- package/src/components/account/avatar-form.tsx +119 -0
- package/src/components/account/credential-proof-form.tsx +76 -0
- package/src/components/account/logout-form.tsx +14 -0
- package/src/components/account/notification-forms.tsx +157 -0
- package/src/components/account/passkey-enrol.tsx +81 -0
- package/src/components/account/passkey-proof-button.tsx +47 -0
- package/src/components/account/push-device-form.tsx +193 -0
- package/src/components/account/relation-forms.tsx +69 -0
- package/src/components/account/reputation-forms.tsx +124 -0
- package/src/components/account/security-activity.tsx +46 -0
- package/src/components/account/sign-in-methods.tsx +166 -0
- package/src/components/account/subscription-forms.tsx +151 -0
- package/src/components/account/two-factor-forms.tsx +226 -0
- package/src/components/account/usercp-forms.tsx +387 -0
- package/src/components/account/usercp-nav.tsx +14 -0
- package/src/components/account/usercp-shell.tsx +34 -0
- package/src/components/admin/admin-forms.tsx +92 -0
- package/src/components/admin/admin-nav.tsx +52 -0
- package/src/components/admin/admin-undo.tsx +32 -0
- package/src/components/admin/api-token-forms.tsx +89 -0
- package/src/components/admin/badge-forms.tsx +97 -0
- package/src/components/admin/branding-forms.tsx +102 -0
- package/src/components/admin/content-forms.tsx +712 -0
- package/src/components/admin/form-bits.tsx +11 -0
- package/src/components/admin/forum-forms.tsx +524 -0
- package/src/components/admin/forum-tree.tsx +454 -0
- package/src/components/admin/group-forms.tsx +646 -0
- package/src/components/admin/mail-test-card.tsx +90 -0
- package/src/components/admin/marketplace-forms.tsx +30 -0
- package/src/components/admin/marketplace-listing.tsx +123 -0
- package/src/components/admin/navigation-forms.tsx +229 -0
- package/src/components/admin/navigation-tree.tsx +442 -0
- package/src/components/admin/oklch-picker.tsx +180 -0
- package/src/components/admin/plugin-forms.tsx +225 -0
- package/src/components/admin/settings-form.tsx +148 -0
- package/src/components/admin/system-forms.tsx +169 -0
- package/src/components/admin/theme-changes.tsx +354 -0
- package/src/components/admin/theme-forms.tsx +636 -0
- package/src/components/admin/theme-palette.tsx +119 -0
- package/src/components/admin/theme-preview.tsx +461 -0
- package/src/components/admin/user-bulk-toolbar.tsx +99 -0
- package/src/components/admin/user-forms.tsx +488 -0
- package/src/components/auth/auth-page.tsx +45 -0
- package/src/components/auth/form-controls.tsx +117 -0
- package/src/components/auth/login-form.tsx +47 -0
- package/src/components/auth/passkey-client.ts +171 -0
- package/src/components/auth/passkey-second-factor.tsx +69 -0
- package/src/components/auth/passkey-sign-in.tsx +61 -0
- package/src/components/auth/register-form.tsx +136 -0
- package/src/components/auth/resend-verification-form.tsx +34 -0
- package/src/components/auth/reset-confirm-form.tsx +43 -0
- package/src/components/auth/reset-request-form.tsx +35 -0
- package/src/components/auth/second-factor-form.tsx +51 -0
- package/src/components/auth/sso-buttons.tsx +47 -0
- package/src/components/board/live-region.tsx +74 -0
- package/src/components/board/search-off-notice.tsx +18 -0
- package/src/components/board/section-page.tsx +114 -0
- package/src/components/content/attachment-field.tsx +51 -0
- package/src/components/content/composer-field.ts +31 -0
- package/src/components/content/composer-ids.ts +6 -0
- package/src/components/content/composer-intents.tsx +27 -0
- package/src/components/content/composer-recovery.tsx +215 -0
- package/src/components/content/edit-post-form.tsx +121 -0
- package/src/components/content/markdown-editor.tsx +590 -0
- package/src/components/content/markdown-syntax.ts +53 -0
- package/src/components/content/mention-token.ts +23 -0
- package/src/components/content/multiquote-button.tsx +32 -0
- package/src/components/content/multiquote-selection.tsx +105 -0
- package/src/components/content/multiquote.ts +125 -0
- package/src/components/content/new-thread-form.tsx +169 -0
- package/src/components/content/poll-edit-form.tsx +96 -0
- package/src/components/content/poll.tsx +89 -0
- package/src/components/content/quote-in-place.tsx +51 -0
- package/src/components/content/reply-form.tsx +113 -0
- package/src/components/content/thanks-button.tsx +65 -0
- package/src/components/content/thread-rating.tsx +143 -0
- package/src/components/install/install-form.tsx +497 -0
- package/src/components/legal/legal-document.tsx +22 -0
- package/src/components/messages/message-forms.tsx +152 -0
- package/src/components/moderation/inline-moderation-form.tsx +158 -0
- package/src/components/moderation/modcp-nav.tsx +15 -0
- package/src/components/moderation/modcp-shell.tsx +41 -0
- package/src/components/moderation/queue-form.tsx +96 -0
- package/src/components/moderation/report-forms.tsx +120 -0
- package/src/components/moderation/signature-lock-form.tsx +83 -0
- package/src/components/moderation/thread-surgery-form.tsx +96 -0
- package/src/components/moderation/thread-tools-form.tsx +137 -0
- package/src/components/moderation/warning-forms.tsx +125 -0
- package/src/components/profile/custom-field.tsx +79 -0
- package/src/components/shell/appearance-icons.tsx +35 -0
- package/src/components/shell/board-notice.tsx +21 -0
- package/src/components/shell/copy-record.ts +20 -0
- package/src/components/shell/copy.tsx +17 -0
- package/src/components/shell/crash-notice.tsx +86 -0
- package/src/components/shell/demo-banner.tsx +49 -0
- package/src/components/shell/group-name-style.tsx +6 -0
- package/src/components/shell/measure.ts +1 -0
- package/src/components/shell/notification-menu.tsx +361 -0
- package/src/components/shell/offline-notice.tsx +29 -0
- package/src/components/shell/onboarding-banner.tsx +39 -0
- package/src/components/shell/page-shell.tsx +167 -0
- package/src/components/shell/panel-list.tsx +95 -0
- package/src/components/shell/panel-nav.tsx +40 -0
- package/src/components/shell/panel-overview.tsx +81 -0
- package/src/components/shell/panel-page.tsx +96 -0
- package/src/components/shell/panel-pagination.tsx +28 -0
- package/src/components/shell/panel-shell.tsx +31 -0
- package/src/components/shell/theme-runtime-style.tsx +6 -0
- package/src/components/shell/theme-switcher.tsx +97 -0
- package/src/components/shell/timezone-probe.tsx +45 -0
- package/src/components/shell/view-tabs.tsx +60 -0
- package/src/config.ts +13 -0
- package/src/server/absent-services.ts +29 -0
- package/src/server/admin-actions.ts +171 -0
- package/src/server/admin-settings-actions.ts +83 -0
- package/src/server/admin-undo-actions.ts +70 -0
- package/src/server/admin-undo.ts +75 -0
- package/src/server/admin.ts +112 -0
- package/src/server/announcements.ts +82 -0
- package/src/server/antispam.ts +310 -0
- package/src/server/api/content.ts +486 -0
- package/src/server/api/http.ts +119 -0
- package/src/server/api/members.ts +109 -0
- package/src/server/api/messages.ts +113 -0
- package/src/server/api/registry.ts +30 -0
- package/src/server/api/search.ts +98 -0
- package/src/server/api/subscriptions.ts +106 -0
- package/src/server/api-auth.ts +66 -0
- package/src/server/api-token-actions.ts +85 -0
- package/src/server/api-tokens-admin.ts +95 -0
- package/src/server/appearance-actions.ts +39 -0
- package/src/server/attachment-download.ts +43 -0
- package/src/server/attachment-embed.ts +63 -0
- package/src/server/attachment-upload-actions.ts +92 -0
- package/src/server/attachments.ts +257 -0
- package/src/server/auth-actions.ts +479 -0
- package/src/server/auth-config.ts +61 -0
- package/src/server/auth-events.ts +92 -0
- package/src/server/auth-form-state.ts +14 -0
- package/src/server/auth-mail.ts +104 -0
- package/src/server/avatars.ts +83 -0
- package/src/server/board-latest-actions.ts +7 -0
- package/src/server/board-latest.tsx +103 -0
- package/src/server/board-offline.ts +23 -0
- package/src/server/board-url.ts +14 -0
- package/src/server/brand-assets.ts +151 -0
- package/src/server/brand-mark.tsx +110 -0
- package/src/server/branding-actions.ts +53 -0
- package/src/server/branding.ts +101 -0
- package/src/server/cache-targets.ts +13 -0
- package/src/server/code-highlighting.ts +33 -0
- package/src/server/container.ts +402 -0
- package/src/server/content-actions.ts +459 -0
- package/src/server/content-admin-actions.ts +492 -0
- package/src/server/content-admin.ts +95 -0
- package/src/server/content-security-policy.ts +35 -0
- package/src/server/context.ts +32 -0
- package/src/server/cookies.ts +139 -0
- package/src/server/credential-proof-actions.ts +42 -0
- package/src/server/credential-proof.ts +35 -0
- package/src/server/current-location.ts +19 -0
- package/src/server/demo-stripe.ts +104 -0
- package/src/server/demo-uploads.ts +28 -0
- package/src/server/demo.ts +80 -0
- package/src/server/discovery.ts +104 -0
- package/src/server/embeds.ts +113 -0
- package/src/server/error-notice.tsx +41 -0
- package/src/server/federation-actions.ts +113 -0
- package/src/server/federation.ts +138 -0
- package/src/server/feed-builder.ts +72 -0
- package/src/server/feed-routes.ts +122 -0
- package/src/server/fixture-actor-source.ts +62 -0
- package/src/server/fixture-forum-repo.ts +59 -0
- package/src/server/fixture-member-profile-repo.ts +30 -0
- package/src/server/fixture-post-repo.ts +108 -0
- package/src/server/fixture-thread-repo.ts +98 -0
- package/src/server/form-state-reporter.ts +34 -0
- package/src/server/form-values.ts +23 -0
- package/src/server/forum-admin-actions.ts +353 -0
- package/src/server/forum-admin.ts +98 -0
- package/src/server/group-admin-actions.ts +341 -0
- package/src/server/group-admin.ts +98 -0
- package/src/server/group-badge-actions.ts +61 -0
- package/src/server/group-badge.ts +62 -0
- package/src/server/group-identity.ts +104 -0
- package/src/server/i18n-catalogs.ts +42 -0
- package/src/server/i18n.ts +69 -0
- package/src/server/image-upload.ts +109 -0
- package/src/server/inline-moderation-actions.ts +129 -0
- package/src/server/install-actions.ts +124 -0
- package/src/server/install.ts +281 -0
- package/src/server/legacy-redirect.ts +83 -0
- package/src/server/legal.ts +43 -0
- package/src/server/location-header.ts +37 -0
- package/src/server/mail-brand.ts +43 -0
- package/src/server/mail-health.ts +41 -0
- package/src/server/mail-send.ts +44 -0
- package/src/server/mail-test-actions.ts +67 -0
- package/src/server/mail-test.ts +56 -0
- package/src/server/markdown-pipeline.ts +31 -0
- package/src/server/marketplace-actions.ts +47 -0
- package/src/server/marketplace-admin.ts +260 -0
- package/src/server/mention-actions.ts +21 -0
- package/src/server/mention-search.ts +35 -0
- package/src/server/message-actions.ts +110 -0
- package/src/server/messages.ts +141 -0
- package/src/server/modcp.ts +125 -0
- package/src/server/moderation-actions.ts +165 -0
- package/src/server/navigation-admin-actions.ts +217 -0
- package/src/server/navigation.ts +112 -0
- package/src/server/nonce.ts +13 -0
- package/src/server/notification-actions.ts +84 -0
- package/src/server/notification-audience.ts +10 -0
- package/src/server/notification-menu-actions.ts +82 -0
- package/src/server/notification-menu.ts +96 -0
- package/src/server/notifications.ts +93 -0
- package/src/server/onboarding-actions.ts +27 -0
- package/src/server/onboarding.ts +89 -0
- package/src/server/page-metadata.ts +14 -0
- package/src/server/passkey-challenge.ts +42 -0
- package/src/server/plugin-admin-actions.ts +232 -0
- package/src/server/plugin-admin.ts +276 -0
- package/src/server/plugin-host.ts +143 -0
- package/src/server/plugin-pages.ts +192 -0
- package/src/server/plugin-panel.ts +49 -0
- package/src/server/plugin-routes.ts +298 -0
- package/src/server/plugin-view.tsx +58 -0
- package/src/server/poll-actions.ts +104 -0
- package/src/server/poll-scope.ts +52 -0
- package/src/server/post-notifications.ts +71 -0
- package/src/server/post-scope.ts +86 -0
- package/src/server/presence.ts +177 -0
- package/src/server/profile-fields.ts +112 -0
- package/src/server/push-actions.ts +113 -0
- package/src/server/push.ts +40 -0
- package/src/server/redirect-back.ts +15 -0
- package/src/server/registration.ts +7 -0
- package/src/server/relation-actions.ts +89 -0
- package/src/server/relations.ts +45 -0
- package/src/server/reply-core.ts +173 -0
- package/src/server/report-actions.ts +165 -0
- package/src/server/report-scope.ts +21 -0
- package/src/server/reputation-actions.ts +146 -0
- package/src/server/reputation-target.ts +49 -0
- package/src/server/reputation.ts +70 -0
- package/src/server/request-fingerprint.ts +65 -0
- package/src/server/safe-path.ts +16 -0
- package/src/server/same-origin.ts +45 -0
- package/src/server/search-page.ts +313 -0
- package/src/server/search.ts +45 -0
- package/src/server/secret-auth.ts +20 -0
- package/src/server/see-other.ts +11 -0
- package/src/server/seed-board.ts +417 -0
- package/src/server/session-actions.ts +78 -0
- package/src/server/session-cookies.ts +124 -0
- package/src/server/session-key.ts +17 -0
- package/src/server/settings.ts +47 -0
- package/src/server/signatures.ts +62 -0
- package/src/server/sso-handshake.ts +79 -0
- package/src/server/stats.ts +63 -0
- package/src/server/subscription-actions.ts +161 -0
- package/src/server/surgery-actions.ts +180 -0
- package/src/server/syndication.ts +77 -0
- package/src/server/system-admin-actions.ts +134 -0
- package/src/server/system-admin.ts +90 -0
- package/src/server/test-container.ts +114 -0
- package/src/server/theme-admin-actions.ts +242 -0
- package/src/server/theme-admin.ts +203 -0
- package/src/server/theme-runtime.ts +89 -0
- package/src/server/theme-style.ts +279 -0
- package/src/server/theme.ts +52 -0
- package/src/server/thread-core.ts +207 -0
- package/src/server/thread-rating-actions.ts +55 -0
- package/src/server/thread-tool-actions.ts +154 -0
- package/src/server/two-factor-actions.ts +178 -0
- package/src/server/two-factor.ts +86 -0
- package/src/server/upgrade-notice.ts +41 -0
- package/src/server/user-admin-actions.ts +572 -0
- package/src/server/user-admin.ts +165 -0
- package/src/server/usercp-actions.ts +263 -0
- package/src/server/usercp-mail.ts +120 -0
- package/src/server/viewer-preferences.ts +64 -0
- package/src/server/warning-actions.ts +122 -0
- package/src/styles/globals.css +969 -0
- package/src/theme/contract.fixture.ts +793 -0
- package/src/view/account-copy.ts +351 -0
- package/src/view/admin-content-copy.ts +66 -0
- package/src/view/admin-copy.ts +106 -0
- package/src/view/admin-forum-tree-copy.ts +40 -0
- package/src/view/admin-group-copy.ts +80 -0
- package/src/view/admin-log.ts +58 -0
- package/src/view/admin-nav.ts +164 -0
- package/src/view/admin-navigation-copy.ts +58 -0
- package/src/view/admin-panel-copy.ts +194 -0
- package/src/view/admin-settings.ts +173 -0
- package/src/view/admin-theme-copy.ts +229 -0
- package/src/view/admin-user-copy.ts +96 -0
- package/src/view/attachments.ts +51 -0
- package/src/view/auth-copy.ts +147 -0
- package/src/view/board-index.ts +167 -0
- package/src/view/board-latest.ts +101 -0
- package/src/view/breadcrumb.ts +50 -0
- package/src/view/contacts.ts +85 -0
- package/src/view/content-copy.ts +118 -0
- package/src/view/contrast.ts +286 -0
- package/src/view/copy.ts +101 -0
- package/src/view/count.ts +8 -0
- package/src/view/discovery-view.ts +74 -0
- package/src/view/editor-toolbar.ts +84 -0
- package/src/view/error-notice.ts +52 -0
- package/src/view/feed.ts +130 -0
- package/src/view/forum-cursor.ts +54 -0
- package/src/view/forum-display.ts +152 -0
- package/src/view/forum-jump.ts +60 -0
- package/src/view/forum-notice.ts +24 -0
- package/src/view/inline-moderation.ts +87 -0
- package/src/view/install-copy.ts +95 -0
- package/src/view/legal.ts +58 -0
- package/src/view/locale.ts +40 -0
- package/src/view/marketplace-panel.ts +51 -0
- package/src/view/member-identity.ts +23 -0
- package/src/view/member-profile.ts +65 -0
- package/src/view/messages.ts +222 -0
- package/src/view/metadata.ts +75 -0
- package/src/view/modcp-nav.ts +76 -0
- package/src/view/moderation-copy.ts +84 -0
- package/src/view/moderation-queue.ts +67 -0
- package/src/view/navigation-arrange.ts +188 -0
- package/src/view/navigation.ts +173 -0
- package/src/view/notification-menu.ts +202 -0
- package/src/view/notifications.ts +84 -0
- package/src/view/onboarding.ts +26 -0
- package/src/view/pager.ts +191 -0
- package/src/view/panel-nav.ts +203 -0
- package/src/view/plugin-panel.ts +42 -0
- package/src/view/post-form.ts +61 -0
- package/src/view/post-link.ts +29 -0
- package/src/view/presence.ts +99 -0
- package/src/view/promotion-rules.ts +52 -0
- package/src/view/redirect-notice.ts +21 -0
- package/src/view/reputation.ts +107 -0
- package/src/view/search-controls.ts +103 -0
- package/src/view/search-results.ts +291 -0
- package/src/view/security-activity.ts +73 -0
- package/src/view/setting-groups.ts +43 -0
- package/src/view/shell.ts +164 -0
- package/src/view/slug-id.ts +12 -0
- package/src/view/sso-hand-off.ts +44 -0
- package/src/view/sso-notices.ts +48 -0
- package/src/view/subscriptions.ts +76 -0
- package/src/view/theme-draft.ts +167 -0
- package/src/view/theme-preference.ts +30 -0
- package/src/view/theme-tokens.ts +333 -0
- package/src/view/thread-view.ts +280 -0
- package/src/view/time.ts +31 -0
- package/src/view/timezone.ts +35 -0
- package/src/view/two-factor.ts +6 -0
- package/src/view/usercp-nav.ts +103 -0
- package/src/view/usercp.ts +196 -0
- package/src/view/warnings.ts +128 -0
- package/src/view/word-filter.ts +5 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import 'server-only'
|
|
2
|
+
|
|
3
|
+
import { idParam } from '@meith/api'
|
|
4
|
+
import { ValidationError } from '@meith/core'
|
|
5
|
+
import { sourceAsMarkdown } from '@meith/markdown'
|
|
6
|
+
import { parseFolder } from '@meith/messages'
|
|
7
|
+
|
|
8
|
+
import { dailyLimitMessage, limitMessage, spendDailyLimit, spendLimit } from '../antispam'
|
|
9
|
+
import { requireMessaging } from '../messages'
|
|
10
|
+
import { type ApiResult, type ApiRoutes, bodyFlag, bodyId, bodyText, notFound } from './http'
|
|
11
|
+
|
|
12
|
+
export const MESSAGE_HANDLERS: ApiRoutes = [
|
|
13
|
+
[
|
|
14
|
+
'GET',
|
|
15
|
+
'/messages',
|
|
16
|
+
async ({ actor, url }): Promise<ApiResult> => {
|
|
17
|
+
const { service, userId } = await requireMessaging(actor)
|
|
18
|
+
const folder = parseFolder(url.searchParams.get('folder') ?? '') ?? 'inbox'
|
|
19
|
+
const before = idParam(url.searchParams.get('before') ?? undefined)
|
|
20
|
+
|
|
21
|
+
const page = await service.list({
|
|
22
|
+
userId,
|
|
23
|
+
folder,
|
|
24
|
+
...(before === null ? {} : { before }),
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
status: 200,
|
|
29
|
+
body: {
|
|
30
|
+
data: page.rows.map((row) => ({
|
|
31
|
+
copyId: row.copyId,
|
|
32
|
+
messageId: row.messageId,
|
|
33
|
+
folder: row.folder,
|
|
34
|
+
role: row.role,
|
|
35
|
+
subject: row.subject,
|
|
36
|
+
sentAt: row.sentAt.toISOString(),
|
|
37
|
+
readAt: row.readAt === null ? null : row.readAt.toISOString(),
|
|
38
|
+
counterparties: [...row.counterparties],
|
|
39
|
+
moreCounterparties: row.moreCounterparties,
|
|
40
|
+
})),
|
|
41
|
+
nextBefore: page.nextBefore,
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
|
|
47
|
+
[
|
|
48
|
+
'GET',
|
|
49
|
+
'/messages/:messageId',
|
|
50
|
+
async ({ actor, params }): Promise<ApiResult> => {
|
|
51
|
+
const messageId = idParam(params.messageId)
|
|
52
|
+
if (messageId === null) return notFound()
|
|
53
|
+
|
|
54
|
+
const { service, userId } = await requireMessaging(actor)
|
|
55
|
+
const detail = await service.open({ messageId, userId })
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
status: 200,
|
|
59
|
+
body: {
|
|
60
|
+
data: {
|
|
61
|
+
id: detail.message.id,
|
|
62
|
+
copyId: detail.copy.id,
|
|
63
|
+
authorUserId: detail.message.authorUserId,
|
|
64
|
+
authorUsername: detail.message.authorUsername,
|
|
65
|
+
subject: detail.message.subject,
|
|
66
|
+
message: sourceAsMarkdown(detail.message.message, detail.message.bodyFormat),
|
|
67
|
+
folder: detail.copy.folder,
|
|
68
|
+
role: detail.copy.role,
|
|
69
|
+
receiptRequested: detail.message.receiptRequested,
|
|
70
|
+
replyToId: detail.message.replyToId,
|
|
71
|
+
sentAt: detail.message.sentAt.toISOString(),
|
|
72
|
+
readAt: detail.copy.readAt === null ? null : detail.copy.readAt.toISOString(),
|
|
73
|
+
participants: detail.participants.map((participant) => ({
|
|
74
|
+
userId: participant.userId,
|
|
75
|
+
username: participant.username,
|
|
76
|
+
role: participant.role,
|
|
77
|
+
readAt: participant.readAt === null ? null : participant.readAt.toISOString(),
|
|
78
|
+
})),
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
|
|
85
|
+
[
|
|
86
|
+
'POST',
|
|
87
|
+
'/messages',
|
|
88
|
+
async ({ actor, body }): Promise<ApiResult> => {
|
|
89
|
+
const { service, userId, username } = await requireMessaging(actor)
|
|
90
|
+
|
|
91
|
+
const limited = await spendLimit({ scope: 'message', actor })
|
|
92
|
+
if (limited !== null && !limited.allowed) throw new ValidationError(limitMessage(limited))
|
|
93
|
+
|
|
94
|
+
const daily = await spendDailyLimit({ scope: 'message_day', actor })
|
|
95
|
+
if (daily !== null && !daily.allowed) {
|
|
96
|
+
throw new ValidationError(dailyLimitMessage('message_day', daily))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const id = await service.send({
|
|
100
|
+
authorUserId: userId,
|
|
101
|
+
authorUsername: username,
|
|
102
|
+
to: bodyText(body, 'to'),
|
|
103
|
+
bcc: bodyText(body, 'bcc'),
|
|
104
|
+
subject: bodyText(body, 'subject'),
|
|
105
|
+
message: bodyText(body, 'message'),
|
|
106
|
+
receiptRequested: bodyFlag(body, 'receiptRequested'),
|
|
107
|
+
replyToId: bodyId(body, 'replyToId'),
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
return { status: 201, body: { data: { id } } }
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import 'server-only'
|
|
2
|
+
|
|
3
|
+
import { ROUTES, type RouteKey, routeKey } from '@meith/api'
|
|
4
|
+
|
|
5
|
+
import { CONTENT_HANDLERS } from './content'
|
|
6
|
+
import type { ApiHandler, ApiRoutes } from './http'
|
|
7
|
+
import { MEMBER_HANDLERS } from './members'
|
|
8
|
+
import { MESSAGE_HANDLERS } from './messages'
|
|
9
|
+
import { SEARCH_HANDLERS } from './search'
|
|
10
|
+
import { SUBSCRIPTION_HANDLERS } from './subscriptions'
|
|
11
|
+
|
|
12
|
+
const DECLARED: ApiRoutes = [
|
|
13
|
+
...CONTENT_HANDLERS,
|
|
14
|
+
...MEMBER_HANDLERS,
|
|
15
|
+
...MESSAGE_HANDLERS,
|
|
16
|
+
...SEARCH_HANDLERS,
|
|
17
|
+
...SUBSCRIPTION_HANDLERS,
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
const HANDLERS = new Map<RouteKey, ApiHandler>(
|
|
21
|
+
DECLARED.map(([method, path, handler]) => [routeKey({ method, path }), handler]),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
export function handlerFor(key: RouteKey): ApiHandler | null {
|
|
25
|
+
return HANDLERS.get(key) ?? null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const IMPLEMENTED_ROUTES: readonly string[] = [...HANDLERS.keys()].sort()
|
|
29
|
+
|
|
30
|
+
export const DECLARED_ROUTES: readonly string[] = ROUTES.map((route) => routeKey(route)).sort()
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import 'server-only'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
isRunnable,
|
|
5
|
+
parseSearchInput,
|
|
6
|
+
readGrouping,
|
|
7
|
+
readMatch,
|
|
8
|
+
readPeriod,
|
|
9
|
+
readSort,
|
|
10
|
+
type SearchCursor,
|
|
11
|
+
searchQueryFrom,
|
|
12
|
+
} from '@meith/search'
|
|
13
|
+
|
|
14
|
+
import { filterWords } from '../../view/word-filter'
|
|
15
|
+
import { activeWordFilter } from '../content-admin'
|
|
16
|
+
import { requireSearch, requireSearchEnabled, searchMinWordLength, searchScopeFor } from '../search'
|
|
17
|
+
import {
|
|
18
|
+
type ApiResult,
|
|
19
|
+
type ApiRoutes,
|
|
20
|
+
badRequest,
|
|
21
|
+
decodeCursor,
|
|
22
|
+
encodeCursor,
|
|
23
|
+
pageLimit,
|
|
24
|
+
} from './http'
|
|
25
|
+
|
|
26
|
+
export const SEARCH_HANDLERS: ApiRoutes = [
|
|
27
|
+
[
|
|
28
|
+
'GET',
|
|
29
|
+
'/search',
|
|
30
|
+
async ({ actor, url }): Promise<ApiResult> => {
|
|
31
|
+
await requireSearchEnabled()
|
|
32
|
+
|
|
33
|
+
const minWordLength = await searchMinWordLength()
|
|
34
|
+
const parsed = parseSearchInput(url.searchParams.get('q') ?? '', minWordLength)
|
|
35
|
+
|
|
36
|
+
if (!isRunnable(parsed)) {
|
|
37
|
+
return badRequest(
|
|
38
|
+
parsed.refusal === 'too-short'
|
|
39
|
+
? `That search term is too short — one word in it has to be at least ${minWordLength} characters.`
|
|
40
|
+
: parsed.refusal === 'too-long'
|
|
41
|
+
? 'That search term is too long.'
|
|
42
|
+
: 'Provide a search term in ?q=.',
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const ids = (key: string): readonly number[] | undefined => {
|
|
47
|
+
const values = url.searchParams
|
|
48
|
+
.getAll(key)
|
|
49
|
+
.map((value) => Number(value))
|
|
50
|
+
.filter((value) => Number.isSafeInteger(value) && value > 0)
|
|
51
|
+
|
|
52
|
+
return values.length === 0 ? undefined : values
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const forumIds = ids('forum')
|
|
56
|
+
const authorUserIds = ids('by')
|
|
57
|
+
|
|
58
|
+
const results = await requireSearch().search(
|
|
59
|
+
searchQueryFrom(
|
|
60
|
+
parsed.terms,
|
|
61
|
+
{
|
|
62
|
+
sort: readSort(url.searchParams.get('sort')),
|
|
63
|
+
match: readMatch(url.searchParams.get('in')),
|
|
64
|
+
grouping: readGrouping(url.searchParams.get('show')),
|
|
65
|
+
period: readPeriod(url.searchParams.get('when')),
|
|
66
|
+
...(forumIds === undefined ? {} : { forumIds }),
|
|
67
|
+
...(authorUserIds === undefined ? {} : { authorUserIds }),
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
limit: pageLimit(url),
|
|
71
|
+
after: decodeCursor<SearchCursor>(url.searchParams.get('after')),
|
|
72
|
+
now: new Date(),
|
|
73
|
+
},
|
|
74
|
+
),
|
|
75
|
+
await searchScopeFor(actor),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
const wordFilter = await activeWordFilter()
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
status: 200,
|
|
82
|
+
body: {
|
|
83
|
+
data: results.hits.map((hit) => ({
|
|
84
|
+
postId: hit.postId,
|
|
85
|
+
threadId: hit.threadId,
|
|
86
|
+
forumId: hit.forumId,
|
|
87
|
+
threadTitle: hit.threadTitle,
|
|
88
|
+
authorUserId: hit.authorUserId,
|
|
89
|
+
authorUsername: hit.authorUsername,
|
|
90
|
+
postedAt: hit.postedAt.toISOString(),
|
|
91
|
+
excerpt: filterWords(hit.excerpt, wordFilter),
|
|
92
|
+
})),
|
|
93
|
+
nextCursor: results.nextCursor === null ? null : encodeCursor(results.nextCursor),
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
]
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import 'server-only'
|
|
2
|
+
|
|
3
|
+
import { idParam } from '@meith/api'
|
|
4
|
+
import type { Actor } from '@meith/authorization'
|
|
5
|
+
import { ValidationError } from '@meith/core'
|
|
6
|
+
import { msg } from '@meith/i18n'
|
|
7
|
+
import { parseSubscriptionTarget, SubscriptionService } from '@meith/subscriptions'
|
|
8
|
+
|
|
9
|
+
import { getContainer } from '../container'
|
|
10
|
+
import { type ApiResult, type ApiRoutes, bodyId, bodyText, notFound, requireUserId } from './http'
|
|
11
|
+
|
|
12
|
+
async function mayView(
|
|
13
|
+
actor: Actor,
|
|
14
|
+
target: 'thread' | 'forum',
|
|
15
|
+
targetId: number,
|
|
16
|
+
): Promise<boolean> {
|
|
17
|
+
const { authorizer, threads, forums } = getContainer()
|
|
18
|
+
|
|
19
|
+
const located = target === 'forum' ? null : await threads.locate(targetId)
|
|
20
|
+
const forumId = target === 'forum' ? targetId : (located?.forumId ?? null)
|
|
21
|
+
if (forumId === null) return false
|
|
22
|
+
|
|
23
|
+
const forum = await forums.findById(forumId)
|
|
24
|
+
if (!forum) return false
|
|
25
|
+
|
|
26
|
+
const matrix = await authorizer.forumMatrix(actor, forumId)
|
|
27
|
+
return target === 'forum'
|
|
28
|
+
? authorizer.can(actor, 'forum.view', { forumId, forum: matrix })
|
|
29
|
+
: authorizer.can(actor, 'thread.view', {
|
|
30
|
+
...(await authorizer.moderatorTargetIn(actor, forumId, matrix)),
|
|
31
|
+
threadAuthorId: located?.authorUserId ?? null,
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function requireSubscriptions(): SubscriptionService {
|
|
36
|
+
const { subscriptions } = getContainer()
|
|
37
|
+
if (subscriptions === null) {
|
|
38
|
+
throw new ValidationError(msg('error.app.board-running-in-memory-sample-data-17'))
|
|
39
|
+
}
|
|
40
|
+
return new SubscriptionService({ subscriptions })
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const SUBSCRIPTION_HANDLERS: ApiRoutes = [
|
|
44
|
+
[
|
|
45
|
+
'GET',
|
|
46
|
+
'/subscriptions',
|
|
47
|
+
async ({ actor }): Promise<ApiResult> => {
|
|
48
|
+
const userId = requireUserId(actor)
|
|
49
|
+
const visibleForumIds = await getContainer().authorizer.visibleForumIds(actor)
|
|
50
|
+
const rows = await requireSubscriptions().list(userId, visibleForumIds)
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
status: 200,
|
|
54
|
+
body: {
|
|
55
|
+
data: rows.map((row) => ({
|
|
56
|
+
target: row.target,
|
|
57
|
+
targetId: row.targetId,
|
|
58
|
+
title: row.title,
|
|
59
|
+
href: row.href,
|
|
60
|
+
mode: row.mode,
|
|
61
|
+
createdAt: row.createdAt.toISOString(),
|
|
62
|
+
pending: row.pending,
|
|
63
|
+
})),
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
|
|
69
|
+
[
|
|
70
|
+
'POST',
|
|
71
|
+
'/subscriptions',
|
|
72
|
+
async ({ actor, body }): Promise<ApiResult> => {
|
|
73
|
+
const userId = requireUserId(actor)
|
|
74
|
+
const target = parseSubscriptionTarget(bodyText(body, 'target'))
|
|
75
|
+
const targetId = bodyId(body, 'targetId')
|
|
76
|
+
if (target === null || targetId === null) return notFound()
|
|
77
|
+
|
|
78
|
+
const requested = bodyText(body, 'mode')
|
|
79
|
+
|
|
80
|
+
const mode = await requireSubscriptions().subscribe({
|
|
81
|
+
userId,
|
|
82
|
+
target,
|
|
83
|
+
targetId,
|
|
84
|
+
mode: requested === '' ? 'instant' : requested,
|
|
85
|
+
mayView: await mayView(actor, target, targetId),
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
return { status: 201, body: { data: { target, targetId, mode } } }
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
|
|
92
|
+
[
|
|
93
|
+
'DELETE',
|
|
94
|
+
'/subscriptions/:target/:targetId',
|
|
95
|
+
async ({ actor, params }): Promise<ApiResult> => {
|
|
96
|
+
const userId = requireUserId(actor)
|
|
97
|
+
const target = parseSubscriptionTarget(params.target ?? '')
|
|
98
|
+
const targetId = idParam(params.targetId)
|
|
99
|
+
if (target === null || targetId === null) return notFound()
|
|
100
|
+
|
|
101
|
+
await requireSubscriptions().unsubscribe({ userId, target, targetId })
|
|
102
|
+
|
|
103
|
+
return { status: 200, body: { data: { target, targetId } } }
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import 'server-only'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type AnonymousRateLimitStore,
|
|
5
|
+
type ApiTokenRecord,
|
|
6
|
+
authenticateToken,
|
|
7
|
+
isScope,
|
|
8
|
+
type RateLimitStore,
|
|
9
|
+
} from '@meith/api'
|
|
10
|
+
import type { Actor } from '@meith/authorization'
|
|
11
|
+
import { env, logger } from '@meith/core'
|
|
12
|
+
import { getDb, PostgresApiTokenRepository, PostgresRateLimitStore } from '@meith/db'
|
|
13
|
+
|
|
14
|
+
import { rateLimitStore } from './antispam'
|
|
15
|
+
import { getContainer } from './container'
|
|
16
|
+
import { countingPrefix } from './request-fingerprint'
|
|
17
|
+
|
|
18
|
+
const ANONYMOUS_SCOPE = 'api_anon'
|
|
19
|
+
|
|
20
|
+
export interface AuthenticatedToken {
|
|
21
|
+
readonly token: ApiTokenRecord
|
|
22
|
+
readonly limits: RateLimitStore
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function apiToken(presented: string): Promise<AuthenticatedToken | null> {
|
|
26
|
+
if (env.DATA_SOURCE === 'fixture') return null
|
|
27
|
+
|
|
28
|
+
const db = getDb()
|
|
29
|
+
const repository = new PostgresApiTokenRepository(db, isScope)
|
|
30
|
+
const outcome = await authenticateToken(presented, repository, new Date())
|
|
31
|
+
|
|
32
|
+
if (!outcome.ok) {
|
|
33
|
+
logger().warn({ reason: outcome.reason }, 'api token rejected')
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await repository.touch(outcome.token.id, new Date()).catch(() => {})
|
|
38
|
+
|
|
39
|
+
return { token: outcome.token, limits: new PostgresRateLimitStore(db) }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function apiActor(userId: number): Promise<Actor | null> {
|
|
43
|
+
return getContainer().actorSource.buildForUser(userId)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function apiGuest(): Promise<Actor> {
|
|
47
|
+
return getContainer().actorSource.buildGuest()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function anonymousSubject(): Promise<string> {
|
|
51
|
+
return (await countingPrefix()) ?? 'unknown'
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function anonymousLimits(): AnonymousRateLimitStore | null {
|
|
55
|
+
const store = rateLimitStore()
|
|
56
|
+
if (store === null) return null
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
async spend(subject, windowStart, cost) {
|
|
60
|
+
return store.spend({ scope: ANONYMOUS_SCOPE, subject }, windowStart, cost)
|
|
61
|
+
},
|
|
62
|
+
async peek(subject, windowStart) {
|
|
63
|
+
return store.peek({ scope: ANONYMOUS_SCOPE, subject }, windowStart)
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use server'
|
|
2
|
+
|
|
3
|
+
import { revalidatePath } from 'next/cache'
|
|
4
|
+
|
|
5
|
+
import { isAppError, logger, publicMessageOf, ValidationError } from '@meith/core'
|
|
6
|
+
import { msg } from '@meith/i18n'
|
|
7
|
+
|
|
8
|
+
import { recordAdminAction, requireAdmin, requireFreshAdmin } from './admin'
|
|
9
|
+
import { apiTokenStore, issueApiToken } from './api-tokens-admin'
|
|
10
|
+
import type { FormState } from './auth-form-state'
|
|
11
|
+
import { getMessageResolver, tr } from './i18n'
|
|
12
|
+
|
|
13
|
+
function field(form: FormData, name: string): string {
|
|
14
|
+
const value = form.get(name)
|
|
15
|
+
return typeof value === 'string' ? value.trim() : ''
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function expiryFrom(raw: string, now: number): Date | null {
|
|
19
|
+
if (raw === '') return null
|
|
20
|
+
|
|
21
|
+
const days = /^\d+$/.test(raw) ? Number(raw) : Number.NaN
|
|
22
|
+
if (!Number.isSafeInteger(days) || days <= 0) {
|
|
23
|
+
throw new ValidationError(msg('error.app.expires-days-must-whole-number'))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return new Date(now + days * 86_400_000)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function refreshTokenList(): void {
|
|
30
|
+
revalidatePath('/admin/api-tokens')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function toState(err: unknown): Promise<FormState> {
|
|
34
|
+
if (isAppError(err)) return { error: publicMessageOf(err, await getMessageResolver()) }
|
|
35
|
+
logger({ module: 'api-token-actions' }).error({ err }, 'api token action failed')
|
|
36
|
+
return { error: await tr('notice.app.something-went-wrong-please-try') }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function issueApiTokenAction(_prev: FormState, form: FormData): Promise<FormState> {
|
|
40
|
+
try {
|
|
41
|
+
const admin = await requireFreshAdmin()
|
|
42
|
+
|
|
43
|
+
const expiresAt = expiryFrom(field(form, 'expiresInDays'), Date.now())
|
|
44
|
+
|
|
45
|
+
const token = await issueApiToken({
|
|
46
|
+
userId: admin.userId,
|
|
47
|
+
name: field(form, 'name'),
|
|
48
|
+
scopes: form.getAll('scopes').filter((s): s is string => typeof s === 'string'),
|
|
49
|
+
expiresAt,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
await recordAdminAction({
|
|
53
|
+
action: 'system.api_token_issued',
|
|
54
|
+
detail: { name: field(form, 'name') },
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
refreshTokenList()
|
|
58
|
+
|
|
59
|
+
return { notice: 'issued', values: { token } }
|
|
60
|
+
} catch (err) {
|
|
61
|
+
return toState(err)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function revokeApiTokenAction(_prev: FormState, form: FormData): Promise<FormState> {
|
|
66
|
+
try {
|
|
67
|
+
await requireAdmin()
|
|
68
|
+
|
|
69
|
+
const id = Number(field(form, 'tokenId'))
|
|
70
|
+
if (!Number.isSafeInteger(id) || id <= 0) return { error: await tr('notice.app.such-token') }
|
|
71
|
+
|
|
72
|
+
const store = apiTokenStore()
|
|
73
|
+
if (store === null) return { error: await tr('notice.app.board-database-api') }
|
|
74
|
+
|
|
75
|
+
const revoked = await store.revoke(id, new Date())
|
|
76
|
+
if (revoked) {
|
|
77
|
+
await recordAdminAction({ action: 'system.api_token_revoked', detail: { tokenId: id } })
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
refreshTokenList()
|
|
81
|
+
return { notice: 'revoked' }
|
|
82
|
+
} catch (err) {
|
|
83
|
+
return toState(err)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { msg } from '@meith/i18n'
|
|
2
|
+
import 'server-only'
|
|
3
|
+
|
|
4
|
+
import { isScope, issueToken, SCOPES, type Scope } from '@meith/api'
|
|
5
|
+
import { ValidationError } from '@meith/core'
|
|
6
|
+
import { type ApiTokenSummary, getDb, PostgresApiTokenRepository } from '@meith/db'
|
|
7
|
+
|
|
8
|
+
import { getContainer } from './container'
|
|
9
|
+
|
|
10
|
+
export function apiTokenStore(): PostgresApiTokenRepository | null {
|
|
11
|
+
return getContainer().dataSource === 'postgres'
|
|
12
|
+
? new PostgresApiTokenRepository(getDb(), isScope)
|
|
13
|
+
: null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ApiTokenRow {
|
|
17
|
+
readonly id: number
|
|
18
|
+
readonly name: string
|
|
19
|
+
readonly username: string
|
|
20
|
+
readonly lookup: string
|
|
21
|
+
readonly scopes: readonly string[]
|
|
22
|
+
readonly createdAt: Date
|
|
23
|
+
readonly expiresAt: Date | null
|
|
24
|
+
readonly lastUsedAt: Date | null
|
|
25
|
+
readonly state: 'live' | 'revoked' | 'expired'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ApiTokenView {
|
|
29
|
+
readonly tokens: readonly ApiTokenRow[]
|
|
30
|
+
readonly scopes: readonly string[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function buildApiTokenView(now: Date): Promise<ApiTokenView | null> {
|
|
34
|
+
const store = apiTokenStore()
|
|
35
|
+
if (store === null) return null
|
|
36
|
+
|
|
37
|
+
const rows = await store.listAll()
|
|
38
|
+
return {
|
|
39
|
+
tokens: rows.map((row) => ({
|
|
40
|
+
id: row.id,
|
|
41
|
+
name: row.name,
|
|
42
|
+
username: row.username,
|
|
43
|
+
lookup: row.lookup,
|
|
44
|
+
scopes: row.scopes,
|
|
45
|
+
createdAt: row.createdAt,
|
|
46
|
+
expiresAt: row.expiresAt,
|
|
47
|
+
lastUsedAt: row.lastUsedAt,
|
|
48
|
+
state: tokenState(row, now),
|
|
49
|
+
})),
|
|
50
|
+
scopes: SCOPES,
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function tokenState(
|
|
55
|
+
row: Pick<ApiTokenSummary, 'revokedAt' | 'expiresAt'>,
|
|
56
|
+
now: Date,
|
|
57
|
+
): ApiTokenRow['state'] {
|
|
58
|
+
if (row.revokedAt !== null) return 'revoked'
|
|
59
|
+
if (row.expiresAt !== null && row.expiresAt <= now) return 'expired'
|
|
60
|
+
return 'live'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface IssueTokenInput {
|
|
64
|
+
readonly userId: number
|
|
65
|
+
readonly name: string
|
|
66
|
+
readonly scopes: readonly string[]
|
|
67
|
+
readonly expiresAt: Date | null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function issueApiToken(input: IssueTokenInput): Promise<string> {
|
|
71
|
+
const store = apiTokenStore()
|
|
72
|
+
if (store === null) throw new ValidationError(msg('error.app.board-database-so-api'))
|
|
73
|
+
|
|
74
|
+
const name = input.name.trim()
|
|
75
|
+
if (name === '' || name.length > 80) {
|
|
76
|
+
throw new ValidationError(msg('error.app.give-token-name-1-80'))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const scopes = input.scopes.filter((scope): scope is Scope => isScope(scope))
|
|
80
|
+
if (scopes.length === 0) {
|
|
81
|
+
throw new ValidationError(msg('error.app.token-needs-at-least-one'))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const issued = issueToken()
|
|
85
|
+
await store.create({
|
|
86
|
+
userId: input.userId,
|
|
87
|
+
name,
|
|
88
|
+
lookup: issued.lookup,
|
|
89
|
+
secretHash: issued.secretHash,
|
|
90
|
+
scopes,
|
|
91
|
+
expiresAt: input.expiresAt,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
return issued.token
|
|
95
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use server'
|
|
2
|
+
|
|
3
|
+
import { cookies } from 'next/headers'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
isColourScheme,
|
|
7
|
+
PREFERENCE_COOKIE_MAX_AGE,
|
|
8
|
+
SCHEME_COOKIE,
|
|
9
|
+
THEME_COOKIE,
|
|
10
|
+
} from '@/view/theme-preference'
|
|
11
|
+
|
|
12
|
+
import { redirectToCurrentPath } from './redirect-back'
|
|
13
|
+
import { getBoardThemeStyle } from './theme-runtime'
|
|
14
|
+
|
|
15
|
+
const COOKIE_OPTIONS = {
|
|
16
|
+
path: '/',
|
|
17
|
+
maxAge: PREFERENCE_COOKIE_MAX_AGE,
|
|
18
|
+
sameSite: 'lax',
|
|
19
|
+
httpOnly: false,
|
|
20
|
+
} as const
|
|
21
|
+
|
|
22
|
+
export async function setAppearanceAction(form: FormData): Promise<void> {
|
|
23
|
+
const jar = await cookies()
|
|
24
|
+
|
|
25
|
+
const scheme = form.get('scheme')
|
|
26
|
+
if (typeof scheme === 'string' && isColourScheme(scheme)) {
|
|
27
|
+
jar.set(SCHEME_COOKIE, scheme, COOKIE_OPTIONS)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const theme = form.get('theme')
|
|
31
|
+
if (typeof theme === 'string' && theme !== '') {
|
|
32
|
+
const { choices } = await getBoardThemeStyle()
|
|
33
|
+
if (choices.some((choice) => choice.key === theme)) {
|
|
34
|
+
jar.set(THEME_COOKIE, theme, COOKIE_OPTIONS)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await redirectToCurrentPath()
|
|
39
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import 'server-only'
|
|
2
|
+
|
|
3
|
+
import { drivers } from '@meith/drivers'
|
|
4
|
+
|
|
5
|
+
import { resolveDownload } from './attachments'
|
|
6
|
+
import { getContainer } from './container'
|
|
7
|
+
import { getActor } from './context'
|
|
8
|
+
|
|
9
|
+
function notFound(): Response {
|
|
10
|
+
return new Response('Not found', { status: 404 })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function contentDisposition(filename: string): string {
|
|
14
|
+
const safe = filename.replace(/[^A-Za-z0-9._ -]/g, '_')
|
|
15
|
+
return `attachment; filename="${safe}"`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function serveAttachment(rawId: string, want: 'file' | 'thumb'): Promise<Response> {
|
|
19
|
+
if (!/^[1-9]\d*$/.test(rawId)) return notFound()
|
|
20
|
+
|
|
21
|
+
const actor = await getActor()
|
|
22
|
+
const grant = await resolveDownload(actor, Number(rawId), want)
|
|
23
|
+
if (grant === null) return notFound()
|
|
24
|
+
|
|
25
|
+
const bytes = await drivers().files.get(grant.key)
|
|
26
|
+
if (bytes === undefined) return notFound()
|
|
27
|
+
|
|
28
|
+
if (want === 'file') {
|
|
29
|
+
await getContainer().attachments?.recordDownload(grant.record.id)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return new Response(bytes as unknown as BodyInit, {
|
|
33
|
+
headers: {
|
|
34
|
+
'Content-Type': grant.contentType,
|
|
35
|
+
'Content-Length': String(bytes.byteLength),
|
|
36
|
+
'Content-Disposition': contentDisposition(grant.filename),
|
|
37
|
+
'X-Content-Type-Options': 'nosniff',
|
|
38
|
+
'Content-Security-Policy': "default-src 'none'; sandbox",
|
|
39
|
+
'X-Frame-Options': 'DENY',
|
|
40
|
+
'Cache-Control': 'private, max-age=0, must-revalidate',
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
}
|