From d6dc7a0b0cb460eecb6faf78cc442d58ab789166 Mon Sep 17 00:00:00 2001 From: Frozen <1884084+xrdavies@users.noreply.github.com> Date: Fri, 10 Apr 2026 22:16:34 +0800 Subject: [PATCH 01/27] feat(db): add media host replacement script --- packages/db/package.json | 3 +- packages/db/scripts/replace-media-host.mjs | 89 ++++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 packages/db/scripts/replace-media-host.mjs diff --git a/packages/db/package.json b/packages/db/package.json index 6093484..9e24ca2 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -16,7 +16,8 @@ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.seed.json --noEmit", "generate": "drizzle-kit generate", "migrate": "drizzle-kit migrate", - "seed": "node --env-file=../../.env --import tsx src/seed.ts" + "seed": "node --env-file=../../.env --import tsx src/seed.ts", + "replace-media-host": "node scripts/replace-media-host.mjs" }, "dependencies": { "@rebase/shared": "workspace:*", diff --git a/packages/db/scripts/replace-media-host.mjs b/packages/db/scripts/replace-media-host.mjs new file mode 100644 index 0000000..4859b71 --- /dev/null +++ b/packages/db/scripts/replace-media-host.mjs @@ -0,0 +1,89 @@ +import { Client } from 'pg'; + +const args = new Map( + process.argv.slice(2).map((entry) => { + const [key, ...rest] = entry.split('='); + return [key, rest.join('=')]; + }), +); + +const normalizeBaseUrl = (value) => value.trim().replace(/\/$/, ''); + +const sourceBaseUrl = normalizeBaseUrl(args.get('--from') || process.env.MEDIA_HOST_FROM || ''); +const targetBaseUrl = normalizeBaseUrl(args.get('--to') || process.env.MEDIA_HOST_TO || ''); +const dryRun = ['1', 'true', 'yes'].includes((args.get('--dry-run') || '').trim().toLowerCase()); +const databaseUrl = process.env.DATABASE_URL || ''; + +if (!databaseUrl) { + console.error('DATABASE_URL is required'); + process.exit(1); +} + +if (!sourceBaseUrl || !targetBaseUrl) { + console.error('Usage: node packages/db/scripts/replace-media-host.mjs --from=https://old-host --to=https://new-host [--dry-run=true]'); + process.exit(1); +} + +const client = new Client({ connectionString: databaseUrl }); + +const listMatchingRows = async () => + client.query( + `select id, object_key, public_url + from assets + where public_url like $1 + order by updated_at desc, created_at desc`, + [`${sourceBaseUrl}/%`], + ); + +const main = async () => { + await client.connect(); + + const before = await listMatchingRows(); + + console.log( + JSON.stringify( + { + dryRun, + sourceBaseUrl, + targetBaseUrl, + matches: before.rowCount, + sample: before.rows.slice(0, 10), + }, + null, + 2, + ), + ); + + if (dryRun || before.rowCount === 0) { + return; + } + + const updated = await client.query( + `update assets + set public_url = replace(public_url, $1, $2), + updated_at = now() + where public_url like $3 + returning id, object_key, public_url`, + [sourceBaseUrl, targetBaseUrl, `${sourceBaseUrl}/%`], + ); + + console.log( + JSON.stringify( + { + updated: updated.rowCount, + sample: updated.rows.slice(0, 10), + }, + null, + 2, + ), + ); +}; + +main() + .catch((error) => { + console.error(error); + process.exitCode = 1; + }) + .finally(async () => { + await client.end().catch(() => undefined); + }); From e536b08b569562347309098de1c630b72de0aec3 Mon Sep 17 00:00:00 2001 From: Frozen <1884084+xrdavies@users.noreply.github.com> Date: Sat, 11 Apr 2026 00:56:47 +0800 Subject: [PATCH 02/27] docs(local): add node and pnpm setup guide --- .nvmrc | 1 + docs/local-development.md | 67 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..5767036 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22.21.1 diff --git a/docs/local-development.md b/docs/local-development.md index b0d956e..c4c62f0 100644 --- a/docs/local-development.md +++ b/docs/local-development.md @@ -19,6 +19,27 @@ For local `astro dev`, the repo intentionally skips the Cloudflare adapter and u ## One-Time Setup +Recommended local toolchain: + +- Node: `22.21.1` via `nvm` +- package manager: `pnpm@10.6.5` +- package manager launcher: `corepack` + +Repository hints: + +- `.nvmrc` pins the recommended local Node version +- `package.json` pins `pnpm@10.6.5` through the `packageManager` field + +Suggested first-time setup: + +```bash +nvm install +nvm use +corepack enable +corepack prepare pnpm@10.6.5 --activate +pnpm install +``` + 1. Copy `.env.example` to `.env` 2. Install dependencies with `pnpm install` 3. Run: @@ -40,6 +61,52 @@ Default local operator credentials: - email: `admin@rebase.local` - password: `RebaseAdmin123456!` +## Node And Package Manager Conventions + +This repository expects: + +- `node` to come from `nvm` +- `pnpm` to match the version pinned in `package.json` +- `corepack` to be the normal way to activate that `pnpm` version + +Quick checks: + +```bash +which node +node -v +which pnpm +pnpm -v +``` + +Healthy output should look like: + +- `node` resolves under `~/.nvm/versions/node/...` +- `pnpm` resolves under the same active Node installation, not `/usr/local/bin/pnpm` + +If `pnpm` is broken because an old global shim is still on the machine, recover with: + +```bash +rm -f /usr/local/bin/pnpm /usr/local/bin/pnpx +hash -r +corepack enable +corepack prepare pnpm@10.6.5 --activate +hash -r +``` + +Then re-check: + +```bash +which pnpm +pnpm -v +``` + +If you only need a temporary workaround, run commands through Corepack directly: + +```bash +corepack pnpm install --frozen-lockfile +corepack pnpm build:admin:prod +``` + ## Daily Development Commands Run the whole stack: From cc6d1e18c26b85ee90e3d97210591d7308aff82b Mon Sep 17 00:00:00 2001 From: Frozen <1884084+xrdavies@users.noreply.github.com> Date: Sat, 11 Apr 2026 01:11:11 +0800 Subject: [PATCH 03/27] docs(cloudflare): clarify workers build commands --- docs/deployment.md | 29 +++++++++++++++++++++++++++++ docs/production-config.md | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/docs/deployment.md b/docs/deployment.md index 304a985..6352a5e 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -90,6 +90,7 @@ Use these settings in Workers > `rebase-web` > Settings > Build: - production branch: `main` - non-production branch builds: enabled - root directory: `/` +- install command: `pnpm install --frozen-lockfile` - build command: `pnpm build:web:prod` - deploy command: `pnpm exec wrangler deploy --config apps/web/dist/server/wrangler.production.json` - non-production branch deploy command: `pnpm exec wrangler versions upload --config apps/web/dist/server/wrangler.production.json` @@ -106,6 +107,12 @@ Required environment variables for `rebase-web` build settings: This avoids Wrangler trying to auto-provision a duplicate `SESSION` KV namespace during deploy. +Cloudflare-specific note: + +- do not wrap the install or build command in `corepack` unless Workers Builds stops recognizing `pnpm` correctly +- the normal dashboard setup should keep `pnpm install --frozen-lockfile` as the install command +- `SESSION_KV_NAMESPACE_ID` and `SESSION_KV_NAMESPACE_PREVIEW_ID` should be configured as plain environment values in Workers Builds, not secrets + ### `rebase-admin` Worker Build Settings Use these settings in Workers > `rebase-admin` > Settings > Build: @@ -114,6 +121,7 @@ Use these settings in Workers > `rebase-admin` > Settings > Build: - production branch: `main` - non-production branch builds: enabled - root directory: `/` +- install command: `pnpm install --frozen-lockfile` - build command: `pnpm build:admin:prod` - deploy command: `pnpm exec wrangler deploy --config apps/admin/wrangler.production.jsonc` - non-production branch deploy command: `pnpm exec wrangler versions upload --config apps/admin/wrangler.production.jsonc` @@ -123,6 +131,17 @@ Recommended build watch paths for `rebase-admin`: - include: `apps/admin/*, packages/shared/*, scripts/deploy/*, package.json, pnpm-lock.yaml, pnpm-workspace.yaml, tsconfig.base.json` - exclude: `docs/*, infra/*, refcode/*, apps/web/*` +Required environment variables for `rebase-admin` build settings: + +- `VITE_API_BASE_URL=https://api.rebase.network` +- `VITE_PUBLIC_SITE_BASE_URL=https://rebase.network` + +Cloudflare-specific note: + +- keep the install command as `pnpm install --frozen-lockfile` +- do not add `corepack` unless the Workers Build image stops exposing the expected `pnpm` version +- `VITE_API_BASE_URL` and `VITE_PUBLIC_SITE_BASE_URL` should be configured as plain environment values, not secrets + ### Root Directory Choice Although Cloudflare supports setting the root directory to a project subdirectory in monorepos, Rebase should keep the root directory at `/` for both Workers because: @@ -135,6 +154,16 @@ Although Cloudflare supports setting the root directory to a project subdirector Workers Builds does not honor custom build configuration declared inside Wrangler config files. Build, deploy, preview deploy, branch control, and watch paths should therefore be configured in the Cloudflare Dashboard for each Worker. +## Recommended Workers Builds Template + +Use this exact pattern for both `rebase-web` and `rebase-admin` unless Cloudflare changes its build image behavior: + +- install command: `pnpm install --frozen-lockfile` +- build command: worker-specific build command from the sections above +- deploy command: worker-specific deploy command from the sections above +- package manager handling: rely on Workers Builds detecting `pnpm` +- `corepack`: keep out of the dashboard commands by default; add it only as a fallback when Cloudflare no longer exposes the expected `pnpm` version + ## Worker Deployment Files Public website: diff --git a/docs/production-config.md b/docs/production-config.md index c8a6255..ad28dd9 100644 --- a/docs/production-config.md +++ b/docs/production-config.md @@ -53,6 +53,7 @@ If a production setting changes, update this file together with the real config - Production branch: `main` - Non-production branch builds: enabled - Root directory: `/` +- Install command: `pnpm install --frozen-lockfile` - Build command: `pnpm build:web:prod` - Deploy command: `pnpm exec wrangler deploy --config apps/web/dist/server/wrangler.production.json` - Non-production deploy command: `pnpm exec wrangler versions upload --config apps/web/dist/server/wrangler.production.json` @@ -66,6 +67,7 @@ Runtime vars and bindings: - `SESSION` KV binding backed by namespace title `rebase-web-session` - `SESSION_KV_NAMESPACE_ID` is configured in Cloudflare Workers Builds environment settings - `SESSION_KV_NAMESPACE_PREVIEW_ID` should normally match the production namespace id unless a dedicated preview namespace is introduced +- `corepack` is not required in the dashboard commands while Workers Builds already detects `pnpm@10.6.5` ### `rebase-admin` @@ -74,6 +76,7 @@ Runtime vars and bindings: - Production branch: `main` - Non-production branch builds: enabled - Root directory: `/` +- Install command: `pnpm install --frozen-lockfile` - Build command: `pnpm build:admin:prod` - Deploy command: `pnpm exec wrangler deploy --config apps/admin/wrangler.production.jsonc` - Non-production deploy command: `pnpm exec wrangler versions upload --config apps/admin/wrangler.production.jsonc` @@ -83,6 +86,7 @@ Build-time targets: - `VITE_API_BASE_URL=https://api.rebase.network` - `VITE_PUBLIC_SITE_BASE_URL=https://rebase.network` +- `corepack` is not required in the dashboard commands while Workers Builds already detects `pnpm@10.6.5` ## Server Inventory From 02ee0c39c3dce737578775966a6f5619d4bd1f17 Mon Sep 17 00:00:00 2001 From: Frozen <1884084+xrdavies@users.noreply.github.com> Date: Sat, 11 Apr 2026 01:25:09 +0800 Subject: [PATCH 04/27] docs(deployment): use recursive watch paths --- docs/deployment.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/deployment.md b/docs/deployment.md index 6352a5e..5d30eed 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -97,8 +97,8 @@ Use these settings in Workers > `rebase-web` > Settings > Build: Recommended build watch paths for `rebase-web`: -- include: `apps/web/*, packages/*, scripts/deploy/*, package.json, pnpm-lock.yaml, pnpm-workspace.yaml, tsconfig.base.json` -- exclude: `docs/*, infra/*, refcode/*, apps/admin/*, apps/api/*` +- include: `apps/web/**, packages/**, scripts/deploy/**, package.json, pnpm-lock.yaml, pnpm-workspace.yaml, tsconfig.base.json` +- exclude: `docs/**, infra/**, refcode/**, apps/admin/**, apps/api/**` Required environment variables for `rebase-web` build settings: @@ -128,8 +128,8 @@ Use these settings in Workers > `rebase-admin` > Settings > Build: Recommended build watch paths for `rebase-admin`: -- include: `apps/admin/*, packages/shared/*, scripts/deploy/*, package.json, pnpm-lock.yaml, pnpm-workspace.yaml, tsconfig.base.json` -- exclude: `docs/*, infra/*, refcode/*, apps/web/*` +- include: `apps/admin/**, packages/shared/**, scripts/deploy/**, package.json, pnpm-lock.yaml, pnpm-workspace.yaml, tsconfig.base.json` +- exclude: `docs/**, infra/**, refcode/**, apps/web/**` Required environment variables for `rebase-admin` build settings: @@ -141,6 +141,7 @@ Cloudflare-specific note: - keep the install command as `pnpm install --frozen-lockfile` - do not add `corepack` unless the Workers Build image stops exposing the expected `pnpm` version - `VITE_API_BASE_URL` and `VITE_PUBLIC_SITE_BASE_URL` should be configured as plain environment values, not secrets +- use recursive `**` glob patterns for build watch paths; single-level `*` patterns do not cover nested files such as `apps/admin/src/**` ### Root Directory Choice From 1507b0a08ad3875526a2a5af3f543613fda53e90 Mon Sep 17 00:00:00 2001 From: Frozen <1884084+xrdavies@users.noreply.github.com> Date: Sat, 11 Apr 2026 02:09:23 +0800 Subject: [PATCH 05/27] feat(contributors): add activity status support --- apps/admin/src/lib/format.ts | 13 +- .../admin/src/views/ContributorEditorPage.vue | 36 +- apps/admin/src/views/ContributorsPage.vue | 72 +- apps/api/src/lib/contributors.ts | 65 +- apps/api/src/routes/admin.ts | 6 +- apps/web/src/components/ContributorCard.astro | 29 +- apps/web/src/pages/contributors.astro | 58 +- docs/content-model.md | 8 + .../db/drizzle/0002_massive_the_hunter.sql | 2 + packages/db/drizzle/meta/0002_snapshot.json | 2473 +++++++++++++++++ packages/db/drizzle/meta/_journal.json | 7 + packages/db/src/schema/index.ts | 2 + packages/shared/src/content.ts | 10 + packages/types/src/content.ts | 1 + 14 files changed, 2668 insertions(+), 114 deletions(-) create mode 100644 packages/db/drizzle/0002_massive_the_hunter.sql create mode 100644 packages/db/drizzle/meta/0002_snapshot.json diff --git a/apps/admin/src/lib/format.ts b/apps/admin/src/lib/format.ts index 39d84ab..d39efaa 100644 --- a/apps/admin/src/lib/format.ts +++ b/apps/admin/src/lib/format.ts @@ -1,4 +1,4 @@ -import type { AssetStatus, ContentStatus, RegistrationMode, StaffAccountStatus } from '@rebase/shared'; +import type { AssetStatus, ContentStatus, ContributorActivityStatus, RegistrationMode, StaffAccountStatus } from '@rebase/shared'; export const formatDateTime = (value?: string | null) => { if (!value) { @@ -61,6 +61,17 @@ export const formatStaffAccountStatus = (status: StaffAccountStatus) => { } }; +export const formatContributorActivityStatus = (status: ContributorActivityStatus) => { + switch (status) { + case 'active': + return '活跃'; + case 'inactive': + return '不活跃'; + default: + return status; + } +}; + const adminRoleLabelMap: Record = { super_admin: '超级管理员', content_editor: '内容编辑', diff --git a/apps/admin/src/views/ContributorEditorPage.vue b/apps/admin/src/views/ContributorEditorPage.vue index 0c9801d..7069f44 100644 --- a/apps/admin/src/views/ContributorEditorPage.vue +++ b/apps/admin/src/views/ContributorEditorPage.vue @@ -4,6 +4,7 @@ import { RouterLink, useRoute, useRouter } from 'vue-router'; import { contentStatusOptions, + contributorActivityStatusOptions, type AdminAssetRecord, type AdminContributorDetailPayload, type AdminContributorRoleRecord, @@ -13,7 +14,7 @@ import { import AssetPickerField from '../components/AssetPickerField.vue'; import MarkdownEditorField from '../components/MarkdownEditorField.vue'; import { adminFetch, adminRequest, getValidationIssues } from '../lib/api'; -import { formatContentStatus, formatDateTime, slugify } from '../lib/format'; +import { formatContentStatus, formatContributorActivityStatus, formatDateTime, slugify } from '../lib/format'; import { getPublicSiteUrl } from '../lib/runtime-config'; interface ContributorFormState extends Omit { @@ -37,6 +38,7 @@ const createBlankForm = (): ContributorFormState => ({ sortOrder: 0, roleIds: [], status: 'draft', + activityStatus: 'active', }); const form = reactive(createBlankForm()); @@ -80,6 +82,7 @@ const applyPayload = (payload: AdminContributorDetailPayload) => { sortOrder: payload.contributor.sortOrder, roleIds: payload.contributor.roleIds, status: payload.contributor.status, + activityStatus: payload.contributor.activityStatus, }); slugTouched.value = true; }; @@ -194,6 +197,10 @@ onMounted(() => void loadRecord());
联系方式
{{ contactSummary }}
+
+
活跃状态
+
{{ formatContributorActivityStatus(form.activityStatus) }}
+
更新时间
{{ detail ? formatDateTime(detail.contributor.updatedAt) : '新建后生成' }}
@@ -305,16 +312,25 @@ onMounted(() => void loadRecord()); -
- 角色分组 -
- -
- {{ fieldIssues.roleIds }} + +
+ +
+ 角色分组 +
+
+ {{ fieldIssues.roleIds }}
diff --git a/apps/admin/src/views/ContributorsPage.vue b/apps/admin/src/views/ContributorsPage.vue index 7f0a6a9..8f7a33a 100644 --- a/apps/admin/src/views/ContributorsPage.vue +++ b/apps/admin/src/views/ContributorsPage.vue @@ -1,9 +1,10 @@ + +