@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,486 @@
|
|
|
1
|
+
import 'server-only'
|
|
2
|
+
|
|
3
|
+
import { idParam } from '@meith/api'
|
|
4
|
+
import type { Actor } from '@meith/authorization'
|
|
5
|
+
import { ForbiddenError, ValidationError } from '@meith/core'
|
|
6
|
+
import { canHoldThreads } from '@meith/forums'
|
|
7
|
+
import { msg } from '@meith/i18n'
|
|
8
|
+
import { sourceAsMarkdown } from '@meith/markdown'
|
|
9
|
+
import { type Poll, PollService } from '@meith/polls'
|
|
10
|
+
import type { ThreadCursor } from '@meith/threads'
|
|
11
|
+
|
|
12
|
+
import { getContainer } from '../container'
|
|
13
|
+
import { emitEvent, filterView, viewerRef } from '../plugin-view'
|
|
14
|
+
import { resolvePollScope } from '../poll-scope'
|
|
15
|
+
import { postEditor, resolvePostScope } from '../post-scope'
|
|
16
|
+
import { resolveReplyTarget, submitReply } from '../reply-core'
|
|
17
|
+
import { resolveThreadTarget, submitThread } from '../thread-core'
|
|
18
|
+
import {
|
|
19
|
+
type ApiResult,
|
|
20
|
+
type ApiRoutes,
|
|
21
|
+
bodyFlag,
|
|
22
|
+
bodyFlagOr,
|
|
23
|
+
bodyId,
|
|
24
|
+
bodyIdList,
|
|
25
|
+
bodyInteger,
|
|
26
|
+
bodyText,
|
|
27
|
+
bodyTime,
|
|
28
|
+
decodeCursor,
|
|
29
|
+
encodeCursor,
|
|
30
|
+
notFound,
|
|
31
|
+
pageLimit,
|
|
32
|
+
requireUserId,
|
|
33
|
+
} from './http'
|
|
34
|
+
|
|
35
|
+
interface ThreadScope {
|
|
36
|
+
readonly scope: ReturnType<ReturnType<typeof getContainer>['authorizer']['contentScope']>
|
|
37
|
+
readonly authors: ReturnType<ReturnType<typeof getContainer>['authorizer']['authorFilter']>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function threadScope(actor: Actor, threadId: number): Promise<ThreadScope | null> {
|
|
41
|
+
const { authorizer, forums, threads } = getContainer()
|
|
42
|
+
|
|
43
|
+
const located = await threads.locate(threadId)
|
|
44
|
+
if (located === null) return null
|
|
45
|
+
|
|
46
|
+
const forum = await forums.findById(located.forumId)
|
|
47
|
+
if (!forum || !canHoldThreads(forum.type)) return null
|
|
48
|
+
|
|
49
|
+
const matrix = await authorizer.forumMatrix(actor, forum.id)
|
|
50
|
+
const target = await authorizer.moderatorTargetIn(actor, forum.id, matrix)
|
|
51
|
+
if (!authorizer.can(actor, 'thread.view', { ...target, threadAuthorId: located.authorUserId })) {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
scope: authorizer.contentScope(actor, target),
|
|
57
|
+
authors: authorizer.authorFilter(actor, target),
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function pollBody(poll: Poll): Record<string, unknown> {
|
|
62
|
+
return {
|
|
63
|
+
id: poll.id,
|
|
64
|
+
threadId: poll.threadId,
|
|
65
|
+
question: poll.question,
|
|
66
|
+
closesAt: poll.closesAt === null ? null : poll.closesAt.toISOString(),
|
|
67
|
+
maxOptions: poll.maxOptions,
|
|
68
|
+
allowRevote: poll.allowRevote,
|
|
69
|
+
publicVotes: poll.publicVotes,
|
|
70
|
+
options: poll.options.map((option) => ({
|
|
71
|
+
id: option.id,
|
|
72
|
+
label: option.label,
|
|
73
|
+
votes: option.votes,
|
|
74
|
+
voters: option.voters.map((voter) => ({
|
|
75
|
+
userId: voter.userId,
|
|
76
|
+
username: voter.username,
|
|
77
|
+
votedAt: voter.votedAt === null ? null : voter.votedAt.toISOString(),
|
|
78
|
+
})),
|
|
79
|
+
})),
|
|
80
|
+
votedOptionId: poll.votedOptionIds[0] ?? null,
|
|
81
|
+
votedOptionIds: poll.votedOptionIds,
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function pollOptionsFrom(body: Record<string, unknown> | null): readonly {
|
|
86
|
+
id: number | null
|
|
87
|
+
label: string
|
|
88
|
+
}[] {
|
|
89
|
+
const value = body?.options
|
|
90
|
+
if (!Array.isArray(value)) return []
|
|
91
|
+
|
|
92
|
+
return value.flatMap((entry) => {
|
|
93
|
+
if (typeof entry !== 'object' || entry === null) return []
|
|
94
|
+
const row = entry as Record<string, unknown>
|
|
95
|
+
const id = typeof row.id === 'number' && Number.isSafeInteger(row.id) ? row.id : null
|
|
96
|
+
return [{ id, label: typeof row.label === 'string' ? row.label : '' }]
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function threadBody(row: {
|
|
101
|
+
readonly id: number
|
|
102
|
+
readonly forumId: number
|
|
103
|
+
readonly title: string
|
|
104
|
+
readonly slug: string
|
|
105
|
+
readonly authorUserId: number | null
|
|
106
|
+
readonly authorUsername: string
|
|
107
|
+
readonly replyCount: number
|
|
108
|
+
readonly viewCount: number
|
|
109
|
+
readonly isSticky: boolean
|
|
110
|
+
readonly isLocked: boolean
|
|
111
|
+
readonly visibility: string
|
|
112
|
+
readonly lastPostAt: Date
|
|
113
|
+
}): Record<string, unknown> {
|
|
114
|
+
return {
|
|
115
|
+
id: row.id,
|
|
116
|
+
forumId: row.forumId,
|
|
117
|
+
title: row.title,
|
|
118
|
+
slug: row.slug,
|
|
119
|
+
authorUserId: row.authorUserId,
|
|
120
|
+
authorUsername: row.authorUsername,
|
|
121
|
+
replyCount: row.replyCount,
|
|
122
|
+
viewCount: row.viewCount,
|
|
123
|
+
isSticky: row.isSticky,
|
|
124
|
+
isLocked: row.isLocked,
|
|
125
|
+
visibility: row.visibility,
|
|
126
|
+
lastPostAt: row.lastPostAt.toISOString(),
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const CONTENT_HANDLERS: ApiRoutes = [
|
|
131
|
+
[
|
|
132
|
+
'GET',
|
|
133
|
+
'/forums',
|
|
134
|
+
async ({ actor }): Promise<ApiResult> => {
|
|
135
|
+
const { authorizer, forums } = getContainer()
|
|
136
|
+
const visible = new Set(await authorizer.forumIdsWhere(actor, 'forum.view'))
|
|
137
|
+
const all = await forums.listAll()
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
status: 200,
|
|
141
|
+
body: {
|
|
142
|
+
data: all
|
|
143
|
+
.filter((forum) => visible.has(forum.id))
|
|
144
|
+
.map((forum) => ({
|
|
145
|
+
id: forum.id,
|
|
146
|
+
title: forum.title,
|
|
147
|
+
slug: forum.slug,
|
|
148
|
+
type: forum.type,
|
|
149
|
+
parentId: forum.parentId ?? null,
|
|
150
|
+
depth: forum.depth,
|
|
151
|
+
})),
|
|
152
|
+
},
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
|
|
157
|
+
[
|
|
158
|
+
'GET',
|
|
159
|
+
'/forums/:forumId/threads',
|
|
160
|
+
async ({ actor, params, url }): Promise<ApiResult> => {
|
|
161
|
+
const forumId = idParam(params.forumId)
|
|
162
|
+
if (forumId === null) return notFound()
|
|
163
|
+
|
|
164
|
+
const { authorizer, forums, threads } = getContainer()
|
|
165
|
+
|
|
166
|
+
const forum = await forums.findById(forumId)
|
|
167
|
+
if (!forum || !canHoldThreads(forum.type)) return notFound()
|
|
168
|
+
|
|
169
|
+
const matrix = await authorizer.forumMatrix(actor, forum.id)
|
|
170
|
+
if (!authorizer.can(actor, 'thread.view', { forumId: forum.id, forum: matrix })) {
|
|
171
|
+
return notFound()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const target = await authorizer.moderatorTargetIn(actor, forum.id, matrix)
|
|
175
|
+
const cursor = decodeCursor<ThreadCursor>(url.searchParams.get('after'))
|
|
176
|
+
const page = await threads.listForum(forum.id, {
|
|
177
|
+
limit: pageLimit(url),
|
|
178
|
+
scope: authorizer.contentScope(actor, target),
|
|
179
|
+
authors: authorizer.authorFilter(actor, target),
|
|
180
|
+
...(cursor === null
|
|
181
|
+
? {}
|
|
182
|
+
: { after: { ...cursor, lastPostAt: new Date(cursor.lastPostAt) } }),
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
status: 200,
|
|
187
|
+
body: {
|
|
188
|
+
data: page.rows.map(threadBody),
|
|
189
|
+
nextCursor: page.nextCursor === null ? null : encodeCursor(page.nextCursor),
|
|
190
|
+
},
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
|
|
195
|
+
[
|
|
196
|
+
'POST',
|
|
197
|
+
'/forums/:forumId/threads',
|
|
198
|
+
async ({ actor, params, body }): Promise<ApiResult> => {
|
|
199
|
+
const forumId = idParam(params.forumId)
|
|
200
|
+
if (forumId === null) return notFound()
|
|
201
|
+
|
|
202
|
+
const resolved = await resolveThreadTarget(actor, forumId)
|
|
203
|
+
const created = await submitThread(actor, resolved, {
|
|
204
|
+
title: bodyText(body, 'title'),
|
|
205
|
+
message: bodyText(body, 'message'),
|
|
206
|
+
prefixId: bodyId(body, 'prefixId'),
|
|
207
|
+
subscribe: bodyFlag(body, 'subscribe'),
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
status: 201,
|
|
212
|
+
body: {
|
|
213
|
+
data: {
|
|
214
|
+
id: created.threadId,
|
|
215
|
+
postId: created.postId,
|
|
216
|
+
slug: created.slug,
|
|
217
|
+
visibility: created.visibility,
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
|
|
224
|
+
[
|
|
225
|
+
'GET',
|
|
226
|
+
'/threads/:threadId',
|
|
227
|
+
async ({ actor, params }): Promise<ApiResult> => {
|
|
228
|
+
const threadId = idParam(params.threadId)
|
|
229
|
+
if (threadId === null) return notFound()
|
|
230
|
+
|
|
231
|
+
const resolved = await threadScope(actor, threadId)
|
|
232
|
+
if (resolved === null) return notFound()
|
|
233
|
+
|
|
234
|
+
const thread = await getContainer().threads.findById(
|
|
235
|
+
threadId,
|
|
236
|
+
resolved.scope,
|
|
237
|
+
resolved.authors,
|
|
238
|
+
)
|
|
239
|
+
if (!thread) return notFound()
|
|
240
|
+
|
|
241
|
+
return { status: 200, body: { data: threadBody(thread) } }
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
|
|
245
|
+
[
|
|
246
|
+
'GET',
|
|
247
|
+
'/threads/:threadId/poll',
|
|
248
|
+
async ({ actor, params }): Promise<ApiResult> => {
|
|
249
|
+
const threadId = idParam(params.threadId)
|
|
250
|
+
if (threadId === null) return notFound()
|
|
251
|
+
|
|
252
|
+
const resolved = await threadScope(actor, threadId)
|
|
253
|
+
if (resolved === null) return notFound()
|
|
254
|
+
|
|
255
|
+
const { polls } = getContainer()
|
|
256
|
+
if (polls === null) return notFound()
|
|
257
|
+
|
|
258
|
+
const poll = await polls.find(threadId, actor.userId)
|
|
259
|
+
if (poll === null) return notFound()
|
|
260
|
+
|
|
261
|
+
return { status: 200, body: { data: pollBody(poll) } }
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
|
|
265
|
+
[
|
|
266
|
+
'POST',
|
|
267
|
+
'/polls/:pollId/votes',
|
|
268
|
+
async ({ actor, params, body }): Promise<ApiResult> => {
|
|
269
|
+
const pollId = idParam(params.pollId)
|
|
270
|
+
const threadId = bodyId(body, 'threadId')
|
|
271
|
+
if (pollId === null || threadId === null) return notFound()
|
|
272
|
+
|
|
273
|
+
const single = bodyId(body, 'optionId')
|
|
274
|
+
const optionIds = [...bodyIdList(body, 'optionIds'), ...(single === null ? [] : [single])]
|
|
275
|
+
|
|
276
|
+
const { polls } = getContainer()
|
|
277
|
+
if (polls === null) return notFound()
|
|
278
|
+
|
|
279
|
+
const scope = await resolvePollScope(actor, threadId)
|
|
280
|
+
if (scope === null) throw new ValidationError(msg('error.app.poll-exist'))
|
|
281
|
+
|
|
282
|
+
await new PollService(polls).vote({
|
|
283
|
+
threadId,
|
|
284
|
+
pollId,
|
|
285
|
+
optionIds,
|
|
286
|
+
userId: requireUserId(actor),
|
|
287
|
+
mayVote: scope.mayVote,
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
return { status: 201, body: { data: { pollId } } }
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
|
|
294
|
+
[
|
|
295
|
+
'PATCH',
|
|
296
|
+
'/polls/:pollId',
|
|
297
|
+
async ({ actor, params, body }): Promise<ApiResult> => {
|
|
298
|
+
const pollId = idParam(params.pollId)
|
|
299
|
+
const threadId = bodyId(body, 'threadId')
|
|
300
|
+
if (pollId === null || threadId === null) return notFound()
|
|
301
|
+
|
|
302
|
+
const { polls } = getContainer()
|
|
303
|
+
if (polls === null) return notFound()
|
|
304
|
+
|
|
305
|
+
requireUserId(actor)
|
|
306
|
+
const scope = await resolvePollScope(actor, threadId)
|
|
307
|
+
if (scope === null) throw new ValidationError(msg('error.app.poll-exist'))
|
|
308
|
+
|
|
309
|
+
const current = await polls.find(threadId, null)
|
|
310
|
+
if (current === null) throw new ValidationError(msg('error.app.poll-exist'))
|
|
311
|
+
|
|
312
|
+
await new PollService(polls).edit({
|
|
313
|
+
threadId,
|
|
314
|
+
pollId,
|
|
315
|
+
edit: {
|
|
316
|
+
question: bodyText(body, 'question'),
|
|
317
|
+
options: pollOptionsFrom(body),
|
|
318
|
+
closesAt: bodyTime(body, 'closesAt'),
|
|
319
|
+
maxOptions: bodyInteger(body, 'maxOptions') ?? current.maxOptions,
|
|
320
|
+
allowRevote: bodyFlagOr(body, 'allowRevote', current.allowRevote),
|
|
321
|
+
publicVotes: bodyFlagOr(body, 'publicVotes', current.publicVotes),
|
|
322
|
+
},
|
|
323
|
+
capabilities: scope.capabilities,
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
const edited = await polls.find(threadId, actor.userId)
|
|
327
|
+
if (edited === null) throw new ValidationError(msg('error.app.poll-exist'))
|
|
328
|
+
|
|
329
|
+
return { status: 200, body: { data: pollBody(edited) } }
|
|
330
|
+
},
|
|
331
|
+
],
|
|
332
|
+
|
|
333
|
+
[
|
|
334
|
+
'GET',
|
|
335
|
+
'/threads/:threadId/posts',
|
|
336
|
+
async ({ actor, params, url }): Promise<ApiResult> => {
|
|
337
|
+
const threadId = idParam(params.threadId)
|
|
338
|
+
if (threadId === null) return notFound()
|
|
339
|
+
|
|
340
|
+
const resolved = await threadScope(actor, threadId)
|
|
341
|
+
if (resolved === null) return notFound()
|
|
342
|
+
|
|
343
|
+
const after = url.searchParams.get('after')
|
|
344
|
+
const afterId = after === null ? null : idParam(after)
|
|
345
|
+
const page = await getContainer().posts.listThread(threadId, {
|
|
346
|
+
...(afterId === null ? {} : { afterId }),
|
|
347
|
+
limit: pageLimit(url),
|
|
348
|
+
scope: resolved.scope,
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
return {
|
|
352
|
+
status: 200,
|
|
353
|
+
body: {
|
|
354
|
+
data: page.rows.map((post) => ({
|
|
355
|
+
id: post.id,
|
|
356
|
+
threadId,
|
|
357
|
+
number: post.number,
|
|
358
|
+
authorUserId: post.authorUserId,
|
|
359
|
+
authorUsername: post.authorUsername,
|
|
360
|
+
message: sourceAsMarkdown(post.message, post.bodyFormat),
|
|
361
|
+
visibility: post.visibility,
|
|
362
|
+
postedAt: post.createdAt.toISOString(),
|
|
363
|
+
})),
|
|
364
|
+
nextAfterId: page.nextAfterId,
|
|
365
|
+
},
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
],
|
|
369
|
+
|
|
370
|
+
[
|
|
371
|
+
'POST',
|
|
372
|
+
'/threads/:threadId/posts',
|
|
373
|
+
async ({ actor, params, body }): Promise<ApiResult> => {
|
|
374
|
+
const threadId = idParam(params.threadId)
|
|
375
|
+
if (threadId === null) return notFound()
|
|
376
|
+
|
|
377
|
+
const resolved = await resolveReplyTarget(actor, threadId)
|
|
378
|
+
const created = await submitReply(actor, resolved, {
|
|
379
|
+
message: bodyText(body, 'message'),
|
|
380
|
+
subscribe: bodyFlag(body, 'subscribe'),
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
return {
|
|
384
|
+
status: 201,
|
|
385
|
+
body: {
|
|
386
|
+
data: {
|
|
387
|
+
id: created.postId,
|
|
388
|
+
threadId: created.threadId,
|
|
389
|
+
visibility: created.visibility,
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
],
|
|
395
|
+
|
|
396
|
+
[
|
|
397
|
+
'PATCH',
|
|
398
|
+
'/threads/:threadId/posts/:postId',
|
|
399
|
+
async ({ actor, params, body }): Promise<ApiResult> => {
|
|
400
|
+
const threadId = idParam(params.threadId)
|
|
401
|
+
const postId = idParam(params.postId)
|
|
402
|
+
if (threadId === null || postId === null) return notFound()
|
|
403
|
+
|
|
404
|
+
const { postWrites } = getContainer()
|
|
405
|
+
if (postWrites === null) return notFound()
|
|
406
|
+
|
|
407
|
+
const scope = await resolvePostScope(threadId, postId, actor)
|
|
408
|
+
if (scope === null) return notFound()
|
|
409
|
+
if (!scope.mayEdit) throw new ForbiddenError(msg('error.app.edit-post'))
|
|
410
|
+
|
|
411
|
+
const userId = requireUserId(actor)
|
|
412
|
+
const revised = await filterView(
|
|
413
|
+
'post.edit.before',
|
|
414
|
+
{ body: bodyText(body, 'message'), reason: bodyText(body, 'reason') },
|
|
415
|
+
{ ...viewerRef(actor), postId, threadId, forumId: scope.target.forum.id },
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
const editor = await postEditor(postWrites)
|
|
419
|
+
const edited = await editor.edit(
|
|
420
|
+
{
|
|
421
|
+
message: revised.body,
|
|
422
|
+
reason: revised.reason ?? '',
|
|
423
|
+
capabilities: scope.capabilities,
|
|
424
|
+
},
|
|
425
|
+
userId,
|
|
426
|
+
scope.target,
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
if (edited.changed) {
|
|
430
|
+
await emitEvent(
|
|
431
|
+
'post.edited',
|
|
432
|
+
{
|
|
433
|
+
postId: edited.postId,
|
|
434
|
+
threadId: edited.threadId,
|
|
435
|
+
forumId: scope.target.forum.id,
|
|
436
|
+
editorId: userId,
|
|
437
|
+
revision: 0,
|
|
438
|
+
},
|
|
439
|
+
viewerRef(actor),
|
|
440
|
+
)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
return {
|
|
444
|
+
status: 200,
|
|
445
|
+
body: {
|
|
446
|
+
data: {
|
|
447
|
+
id: edited.postId,
|
|
448
|
+
threadId: edited.threadId,
|
|
449
|
+
changed: edited.changed,
|
|
450
|
+
heldForApproval: edited.heldForApproval,
|
|
451
|
+
},
|
|
452
|
+
},
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
],
|
|
456
|
+
|
|
457
|
+
[
|
|
458
|
+
'DELETE',
|
|
459
|
+
'/threads/:threadId/posts/:postId',
|
|
460
|
+
async ({ actor, params }): Promise<ApiResult> => {
|
|
461
|
+
const threadId = idParam(params.threadId)
|
|
462
|
+
const postId = idParam(params.postId)
|
|
463
|
+
if (threadId === null || postId === null) return notFound()
|
|
464
|
+
|
|
465
|
+
const { postWrites } = getContainer()
|
|
466
|
+
if (postWrites === null) return notFound()
|
|
467
|
+
|
|
468
|
+
const scope = await resolvePostScope(threadId, postId, actor)
|
|
469
|
+
if (scope === null) return notFound()
|
|
470
|
+
if (!scope.mayDelete) throw new ForbiddenError(msg('error.app.delete-post'))
|
|
471
|
+
|
|
472
|
+
const userId = requireUserId(actor)
|
|
473
|
+
const editor = await postEditor(postWrites)
|
|
474
|
+
const removed = await editor.softDelete(userId, scope.target, {
|
|
475
|
+
bypassesLock: scope.bypassesLock,
|
|
476
|
+
})
|
|
477
|
+
|
|
478
|
+
return {
|
|
479
|
+
status: 200,
|
|
480
|
+
body: {
|
|
481
|
+
data: { id: removed.postId, threadId: removed.threadId, changed: removed.changed },
|
|
482
|
+
},
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
],
|
|
486
|
+
]
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import 'server-only'
|
|
2
|
+
|
|
3
|
+
import type { ApiTokenRecord, Method, RouteSpec } from '@meith/api'
|
|
4
|
+
import type { Actor } from '@meith/authorization'
|
|
5
|
+
import { ForbiddenError } from '@meith/core'
|
|
6
|
+
import { currentRequestId } from '@meith/core/logger'
|
|
7
|
+
import { msg } from '@meith/i18n'
|
|
8
|
+
|
|
9
|
+
export interface ApiRequest {
|
|
10
|
+
readonly actor: Actor
|
|
11
|
+
readonly token: ApiTokenRecord | null
|
|
12
|
+
readonly params: Readonly<Record<string, string>>
|
|
13
|
+
readonly url: URL
|
|
14
|
+
readonly body: Record<string, unknown> | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ApiResult {
|
|
18
|
+
readonly status: number
|
|
19
|
+
readonly body: unknown
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type ApiHandler = (request: ApiRequest) => Promise<ApiResult>
|
|
23
|
+
|
|
24
|
+
export type ApiRoute = readonly [Method, RouteSpec['path'], ApiHandler]
|
|
25
|
+
|
|
26
|
+
export type ApiRoutes = readonly ApiRoute[]
|
|
27
|
+
|
|
28
|
+
export const JSON_MEDIA_TYPE = 'application/json; charset=utf-8'
|
|
29
|
+
|
|
30
|
+
export const SPEC_CACHE = 'public, max-age=300, stale-while-revalidate=3600'
|
|
31
|
+
|
|
32
|
+
export const DEFAULT_PAGE = 25
|
|
33
|
+
export const MAX_PAGE = 100
|
|
34
|
+
|
|
35
|
+
export function failure(status: number, code: string, message: string): ApiResult {
|
|
36
|
+
return {
|
|
37
|
+
status,
|
|
38
|
+
body: { error: { code, message, requestId: currentRequestId() ?? null } },
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function notFound(): ApiResult {
|
|
43
|
+
return failure(404, 'not_found', 'No such resource.')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function requireUserId(actor: Actor): number {
|
|
47
|
+
if (actor.userId === null) throw new ForbiddenError(msg('error.app.must-logged'))
|
|
48
|
+
return actor.userId
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function badRequest(message: string): ApiResult {
|
|
52
|
+
return failure(400, 'bad_request', message)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function pageLimit(url: URL): number {
|
|
56
|
+
const raw = url.searchParams.get('limit')
|
|
57
|
+
if (raw === null) return DEFAULT_PAGE
|
|
58
|
+
const parsed = Number(raw)
|
|
59
|
+
if (!Number.isSafeInteger(parsed) || parsed < 1) return DEFAULT_PAGE
|
|
60
|
+
return Math.min(parsed, MAX_PAGE)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function encodeCursor(cursor: unknown): string {
|
|
64
|
+
return Buffer.from(JSON.stringify(cursor), 'utf8').toString('base64url')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function decodeCursor<T>(raw: string | null): T | null {
|
|
68
|
+
if (raw === null) return null
|
|
69
|
+
try {
|
|
70
|
+
return JSON.parse(Buffer.from(raw, 'base64url').toString('utf8')) as T
|
|
71
|
+
} catch {
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function bodyText(body: Record<string, unknown> | null, name: string): string {
|
|
77
|
+
const value = body?.[name]
|
|
78
|
+
return typeof value === 'string' ? value : ''
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function bodyFlag(body: Record<string, unknown> | null, name: string): boolean {
|
|
82
|
+
return body?.[name] === true
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function bodyId(body: Record<string, unknown> | null, name: string): number | null {
|
|
86
|
+
const value = body?.[name]
|
|
87
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0) return null
|
|
88
|
+
return value
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function bodyInteger(body: Record<string, unknown> | null, name: string): number | null {
|
|
92
|
+
const value = body?.[name]
|
|
93
|
+
return typeof value === 'number' && Number.isSafeInteger(value) ? value : null
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function bodyFlagOr(
|
|
97
|
+
body: Record<string, unknown> | null,
|
|
98
|
+
name: string,
|
|
99
|
+
fallback: boolean,
|
|
100
|
+
): boolean {
|
|
101
|
+
const value = body?.[name]
|
|
102
|
+
return typeof value === 'boolean' ? value : fallback
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function bodyIdList(body: Record<string, unknown> | null, name: string): readonly number[] {
|
|
106
|
+
const value = body?.[name]
|
|
107
|
+
if (!Array.isArray(value)) return []
|
|
108
|
+
return value.filter(
|
|
109
|
+
(entry): entry is number =>
|
|
110
|
+
typeof entry === 'number' && Number.isSafeInteger(entry) && entry > 0,
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function bodyTime(body: Record<string, unknown> | null, name: string): Date | null {
|
|
115
|
+
const value = body?.[name]
|
|
116
|
+
if (typeof value !== 'string') return null
|
|
117
|
+
const at = new Date(value)
|
|
118
|
+
return Number.isNaN(at.getTime()) ? null : at
|
|
119
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import 'server-only'
|
|
2
|
+
|
|
3
|
+
import { idParam } from '@meith/api'
|
|
4
|
+
import { ForbiddenError, ValidationError } from '@meith/core'
|
|
5
|
+
import { msg } from '@meith/i18n'
|
|
6
|
+
import { parseRating } from '@meith/reputation'
|
|
7
|
+
|
|
8
|
+
import { getContainer } from '../container'
|
|
9
|
+
import { reputationService, reputationSettings, viewerRaterLimits } from '../reputation'
|
|
10
|
+
import { requireRateablePost } from '../reputation-target'
|
|
11
|
+
import {
|
|
12
|
+
type ApiResult,
|
|
13
|
+
type ApiRoutes,
|
|
14
|
+
bodyId,
|
|
15
|
+
bodyInteger,
|
|
16
|
+
bodyText,
|
|
17
|
+
notFound,
|
|
18
|
+
requireUserId,
|
|
19
|
+
} from './http'
|
|
20
|
+
|
|
21
|
+
export const MEMBER_HANDLERS: ApiRoutes = [
|
|
22
|
+
[
|
|
23
|
+
'GET',
|
|
24
|
+
'/me',
|
|
25
|
+
async ({ actor, token }): Promise<ApiResult> => {
|
|
26
|
+
const userId = requireUserId(actor)
|
|
27
|
+
const profile = await getContainer().memberProfiles.findPublicById(userId)
|
|
28
|
+
if (!profile) return notFound()
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
status: 200,
|
|
32
|
+
body: {
|
|
33
|
+
data: {
|
|
34
|
+
userId,
|
|
35
|
+
username: profile.username,
|
|
36
|
+
scopes: token === null ? [] : [...token.scopes],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
|
|
43
|
+
[
|
|
44
|
+
'GET',
|
|
45
|
+
'/members/:userId',
|
|
46
|
+
async ({ actor, params }): Promise<ApiResult> => {
|
|
47
|
+
const userId = idParam(params.userId)
|
|
48
|
+
if (userId === null) return notFound()
|
|
49
|
+
|
|
50
|
+
const { authorizer, memberProfiles } = getContainer()
|
|
51
|
+
if (!authorizer.can(actor, 'profile.view')) return notFound()
|
|
52
|
+
|
|
53
|
+
const profile = await memberProfiles.findPublicById(userId)
|
|
54
|
+
if (!profile) return notFound()
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
status: 200,
|
|
58
|
+
body: {
|
|
59
|
+
data: {
|
|
60
|
+
id: profile.id,
|
|
61
|
+
username: profile.username,
|
|
62
|
+
title: profile.title,
|
|
63
|
+
postCount: profile.postCount,
|
|
64
|
+
joinedAt: profile.createdAt.toISOString(),
|
|
65
|
+
lastActiveAt: profile.lastActiveAt === null ? null : profile.lastActiveAt.toISOString(),
|
|
66
|
+
location: profile.location,
|
|
67
|
+
website: profile.website,
|
|
68
|
+
bio: profile.bio,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
|
|
75
|
+
[
|
|
76
|
+
'POST',
|
|
77
|
+
'/members/:userId/reputation',
|
|
78
|
+
async ({ actor, params, body }): Promise<ApiResult> => {
|
|
79
|
+
const userId = idParam(params.userId)
|
|
80
|
+
if (userId === null) return notFound()
|
|
81
|
+
|
|
82
|
+
const raterId = requireUserId(actor)
|
|
83
|
+
const service = reputationService()
|
|
84
|
+
if (service === null) {
|
|
85
|
+
throw new ForbiddenError(msg('error.app.board-running-in-memory-sample-data'))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const submitted = bodyInteger(body, 'points')
|
|
89
|
+
const points = submitted === null ? null : parseRating(String(submitted))
|
|
90
|
+
if (points === null) throw new ValidationError(msg('error.app.rating'))
|
|
91
|
+
|
|
92
|
+
const postId = bodyId(body, 'postId')
|
|
93
|
+
await requireRateablePost(actor, userId, postId)
|
|
94
|
+
const [settings, limits] = await Promise.all([reputationSettings(), viewerRaterLimits(actor)])
|
|
95
|
+
|
|
96
|
+
await service.give({
|
|
97
|
+
userId,
|
|
98
|
+
givenByUserId: raterId,
|
|
99
|
+
postId,
|
|
100
|
+
points,
|
|
101
|
+
comment: bodyText(body, 'comment'),
|
|
102
|
+
settings,
|
|
103
|
+
limits,
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
return { status: 201, body: { data: { userId } } }
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
]
|