Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# 时光邮局(post)
# 时光邮局(someday)

在未来某个日期时间,把一封信通过邮件寄到指定邮箱 —— 小圈子多用户的定时寄信服务。线上域名:post.oneboy.app。
在未来某个日期时间,把一封信通过邮件寄到指定邮箱 —— 小圈子多用户的定时寄信服务。线上域名:someday.oneboy.app。

## 技术栈

- monorepo:pnpm workspace,`web/` + `worker/`
- `web/`(`@post/web`):React + Vite + TypeScript,构建产物由 Workers Static Assets 托管
- `worker/`(`@post/worker`):Hono + Cloudflare Workers,D1 数据库,cron 定时调度(`*/5 * * * *`)
- `web/`(`@someday/web`):React + Vite + TypeScript,构建产物由 Workers Static Assets 托管
- `worker/`(`@someday/worker`):Hono + Cloudflare Workers,D1 数据库,cron 定时调度(`*/5 * * * *`)

## 本地开发

Expand Down Expand Up @@ -37,7 +37,7 @@ cp worker/.dev.vars.example worker/.dev.vars

### 表前缀(TABLE_PREFIX)

post 使用组织共享 D1,表名一律带前缀(ONE-269)。三态解析:
someday 使用组织共享 D1,表名一律带前缀(ONE-269)。三态解析:

- 未配置(`undefined`)→ 默认 `post_`(共享 D1 零配置隔离,安全默认);
- 显式空串 `""` → 无前缀(部署方自担表名冲突风险);
Expand Down Expand Up @@ -65,14 +65,14 @@ schema 的唯一可信源是 `worker/src/db/migrations.ts` 里按前缀参数化
| 表名生成入口 | 只经 `worker/src/types.ts` 的 `migrationsTable(prefix)` 一处生成,严禁散落拼接 |
| 账本结构 | `name TEXT PRIMARY KEY, applied_at INTEGER NOT NULL DEFAULT (unixepoch())` |

**历史已塌缩**:post 无生产数据,历史不逐级展开,只有一条 `schema_v1` = 当前最终 schema
**历史已塌缩**:someday 无生产数据,历史不逐级展开,只有一条 `schema_v1` = 当前最终 schema
(6 表 + 4 索引)。今后的变更从 `schema_v2` 起追加。

**runner 语义**(`worker/src/lib/migrations-runner.ts`,两处 setup 入口共用):

1. 按 TABLE_PREFIX 三态解析生效前缀;
2. 防静默切换:库里已按其他前缀初始化时中止报错(信号两路:post 独有三表齐全的业务表族,
以及可归属到 post 的账本表 `_<前缀核>_schema_migrations`);共享库里 shortlink / Zeta
2. 防静默切换:库里已按其他前缀初始化时中止报错(信号两路:someday 独有三表齐全的业务表族,
以及可归属到 someday 的账本表 `_<前缀核>_schema_migrations`);共享库里 shortlink / Zeta
等其他项目的账本表不会被误判;
3. 建账本表(`IF NOT EXISTS`)→ 读已应用集合 → 按序执行未记录的迁移,成功后立即写一行;
4. 首个失败即停、报错,**失败项不落账**(修好后重跑会重试它)。
Expand All @@ -85,7 +85,7 @@ schema 的唯一可信源是 `worker/src/db/migrations.ts` 里按前缀参数化
(重初始化由用户在合并关口执行,团队不碰线上 D1);
- 不新增任何 `PRAGMA table_info` 探测式升级代码。

**默认 settings 种子**:post 没有默认 settings 种子数据(`{prefix}system_settings` 的键都由
**默认 settings 种子**:someday 没有默认 settings 种子数据(`{prefix}system_settings` 的键都由
业务按需写入),因此没有种子迁移;`setup` 的后置步骤仍是老的两件事——`schema_v1` 落库后
由 `closeSetup()` 写 `setup_page_enabled=0`,再由第一个注册用户成为管理员。

Expand Down Expand Up @@ -122,12 +122,12 @@ pnpm test # worker 单测(vitest)
- Worker secrets(部署后执行一次):`wrangler secret put JWT_SECRET`、`wrangler secret put SETUP_SECRET`
- 首次部署建表:`POST /api/setup` 自动按生效前缀内联建表(无需 `wrangler d1 migrations apply`)

本地手动部署:`pnpm deploy`(内部替换 wrangler.toml 占位符后 `wrangler deploy`)。域名 `post.oneboy.app` 的绑定在部署阶段处理。
本地手动部署:`pnpm deploy`(内部替换 wrangler.toml 占位符后 `wrangler deploy`)。域名 `someday.oneboy.app` 的绑定在部署阶段处理。

## 目录结构

```
web/ 前端(@post/web)
worker/ Cloudflare Worker(@post/worker,Hono + D1 + KV + cron)
web/ 前端(@someday/web)
worker/ Cloudflare Worker(@someday/worker,Hono + D1 + KV + cron)
scripts/ 部署辅助脚本
```
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "post",
"name": "someday",
"version": "0.1.0",
"private": true,
"type": "module",
"description": "时光邮局 — 在未来某个日期时间,把一封信寄到指定邮箱(post.oneboy.app)",
"description": "时光邮局 — 在未来某个日期时间,把一封信寄到指定邮箱(someday.oneboy.app)",
"scripts": {
"dev": "concurrently \"pnpm dev:worker\" \"pnpm dev:web\"",
"dev:web": "pnpm --filter @post/web dev",
"dev:worker": "pnpm --filter @post/worker dev",
"build": "pnpm --filter @post/web build && pnpm --filter @post/worker build",
"build:web": "pnpm --filter @post/web build",
"build:worker": "pnpm --filter @post/worker build",
"typecheck": "pnpm --filter @post/web typecheck && pnpm --filter @post/worker typecheck",
"test": "pnpm --filter @post/web test && pnpm --filter @post/worker test",
"dev:web": "pnpm --filter @someday/web dev",
"dev:worker": "pnpm --filter @someday/worker dev",
"build": "pnpm --filter @someday/web build && pnpm --filter @someday/worker build",
"build:web": "pnpm --filter @someday/web build",
"build:worker": "pnpm --filter @someday/worker build",
"typecheck": "pnpm --filter @someday/web typecheck && pnpm --filter @someday/worker typecheck",
"test": "pnpm --filter @someday/web test && pnpm --filter @someday/worker test",
"deploy": "pnpm build:web && node scripts/deploy.mjs"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@post/web",
"name": "@someday/web",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion web/src/api/mock/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const mockTwoFaApi: TwoFaApi = {
state.twofa.pendingTotpSecret = TOTP_SECRET;
return {
secret: TOTP_SECRET,
uri: `otpauth://totp/post:${account.email}?secret=${TOTP_SECRET}&issuer=post`,
uri: `otpauth://totp/someday:${account.email}?secret=${TOTP_SECRET}&issuer=someday`,
};
},
async totpEnable(code) {
Expand Down
4 changes: 2 additions & 2 deletions web/src/api/mock/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export interface MockState {
const DEFAULT_SMTP: SmtpConfig = {
host: "smtp.example.com",
port: 465,
username: "post@example.com",
username: "someday@example.com",
password: "", // 空串表示未配置(脱敏回显也不含明文)
password_set: false,
from: "post@example.com",
from: "someday@example.com",
from_name: "时光邮局",
};

Expand Down
4 changes: 2 additions & 2 deletions web/src/components/settings/smtp-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function SmtpSection() {
name="smtp_username"
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="post@example.com"
placeholder="someday@example.com"
autoComplete="off"
/>
</div>
Expand Down Expand Up @@ -196,7 +196,7 @@ export function SmtpSection() {
name="smtp_from"
value={from}
onChange={(e) => setFrom(e.target.value)}
placeholder="post@example.com"
placeholder="someday@example.com"
autoComplete="off"
/>
</div>
Expand Down
6 changes: 3 additions & 3 deletions web/src/pages/about.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ describe("关于页内容族(ONE-337)", () => {
expect(screen.getByText(/Zustand/)).toBeInTheDocument();
});

it("开源地址固定为 WorkerHub/post,外链新开页并带 noopener", () => {
it("开源地址固定为 WorkerHub/someday,外链新开页并带 noopener", () => {
renderAppAt("/about");

const repo = screen.getByRole("link", { name: /github\.com\/WorkerHub\/post/ });
const repo = screen.getByRole("link", { name: /github\.com\/WorkerHub\/someday/ });
expect(repo).toHaveAttribute("href", REPO_URL);
expect(REPO_URL).toBe("https://github.com/WorkerHub/post");
expect(REPO_URL).toBe("https://github.com/WorkerHub/someday");
expect(repo).toHaveAttribute("target", "_blank");
expect(repo.getAttribute("rel")).toContain("noopener");
});
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { APP_BUILD_TIME, APP_VERSION } from "@/lib/version";
// 不在本页写死;产品名与 web/index.html 的 <title> 文案保持一致。
export const PRODUCT_NAME = "时光邮局";
export const PRODUCT_TAGLINE = "小圈子多用户的定时寄信服务";
export const REPO_URL = "https://github.com/WorkerHub/post";
export const REPO_URL = "https://github.com/WorkerHub/someday";

const INTRO =
"写下想说的话,挑一个未来的日期,到那天它会自动寄到对方的邮箱。信可以只寄给指定的人,也可以公开到信墙,让路过的人一起读。";
Expand Down Expand Up @@ -160,7 +160,7 @@ export default function AboutPage() {
className="mt-3 inline-flex items-center gap-1.5 text-sm text-seal-600 underline-offset-4 hover:underline"
>
<ExternalLink className="size-4" />
github.com/WorkerHub/post
github.com/WorkerHub/someday
</a>
</CardContent>
</Card>
Expand Down
2 changes: 1 addition & 1 deletion worker/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@post/worker",
"name": "@someday/worker",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion worker/src/routes/auth2fa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ auth2faRoutes.post("/passkey/register/options", async (c) => {
: [];

const options = await generateRegistrationOptions({
rpName: "post",
rpName: "someday",
rpID: new URL(c.req.url).hostname,
userName: user.email,
userDisplayName: user.email,
Expand Down
2 changes: 1 addition & 1 deletion worker/src/services/smtp-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function sendSmtpMessage(
message: SmtpMessage,
): Promise<{ success: boolean; error?: string }> {
const from = message.from || "noreply@example.com";
const fromName = (message.fromName || "post").replace(/[\r\n]/g, "");
const fromName = (message.fromName || "someday").replace(/[\r\n]/g, "");
const isImplicitTls = config.port === 465;

const socket: any = connect({ hostname: config.host, port: config.port }, {
Expand Down
2 changes: 1 addition & 1 deletion worker/src/services/twofa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function generateTOTPSecret(
const bytes = new Uint8Array(20);
crypto.getRandomValues(bytes);
const secret = base32Encode(bytes);
const uri = `otpauth://totp/post:${encodeURIComponent(email)}?secret=${secret}&issuer=post&algorithm=SHA1&digits=6&period=30`;
const uri = `otpauth://totp/someday:${encodeURIComponent(email)}?secret=${secret}&issuer=someday&algorithm=SHA1&digits=6&period=30`;
return { secret, uri };
}

Expand Down
2 changes: 1 addition & 1 deletion worker/test/admin-smtp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("管理后台 SMTP 配置与测试邮件(ONE-176)", () => {
username: "noreply@example.com",
password: "super-secret-password",
from: "noreply@example.com",
from_name: "post",
from_name: "someday",
},
admin,
),
Expand Down
2 changes: 1 addition & 1 deletion worker/test/totp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe("TOTP 2FA(eNotify 移植)", () => {
);
expect(setup.status).toBe(200);
expect(setup.body.secret).toMatch(/^[A-Z2-7]{32}$/);
expect(setup.body.uri).toContain("otpauth://totp/post:");
expect(setup.body.uri).toContain("otpauth://totp/someday:");

// 错误验证码 enable 失败
const badEnable = await request(
Expand Down
2 changes: 1 addition & 1 deletion worker/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "post"
name = "someday"
main = "src/index.ts"
compatibility_date = "2026-05-01"
compatibility_flags = ["nodejs_compat"]
Expand Down
Loading