Files
wmailhub/docs/05_DATA_MODEL.md
T
bigcode 7370cce784 feat: v2.1.0 界面与凭据改进 —— 单一 API/MCP Key、邮件 Markdown 正文、/inboxs 域名筛选、暗色主题
- 单一 Key:API 与 MCP 共用一个 wmh_ Key,凭据迁移至 settings 表(0004 删除 api_credentials)
- Markdown:入库时 HTML→Markdown(mailhook 同思路),webhook payload 新增 markdown 字段
- /emails 路由改为 /inboxs 并支持域名筛选;设置按钮移入头像下拉
- 主题切换按钮(头像左侧,亮/暗持久化);设置模态仅 全局 Webhook/账号密码 两 tab 且高度限屏
- 列表操作列按钮加 SVG 图标;mailboxes 去 Webhook 列;最近邮件加收件人列
2026-09-30 13:27:28 +08:00

2.8 KiB

数据模型(v2,docs/11 §13)

核心实体:CloudflareAccount、Domain、Mailbox、Email、EmailAttachment、Webhook(三级配置)、WebhookDelivery、OAuthConnection、WorkerCredential。

Node 作为邮件链路核心模型已删除(旧 nodes / node_credentials 表由迁移 0003 移除, 账号实体更名为 cloudflare_accounts,凭据更换为 worker_credentials)。

cloudflare_accounts

id, name, cloudflare_account_id, worker_id, status, provision_steps, created_at, updated_at

status:pending_oauth | provisioning | active | error | revoked。 worker_id 同时是 Email Worker 脚本名与 Worker -> Console 的身份 ID。

domains

id, cloudflare_account_id, account_id, name, status, worker_id, zone_id,
webhook_url, webhook_headers, webhook_key_enc, setup_error, created_at, updated_at

status:pending(未配置 Email Workers)| active | error。

mailboxes

id, domain_id, address, status, retention_seconds, is_catch_all,
webhook_url, webhook_headers, webhook_key_enc, created_at, updated_at

emails

id, account_id, mailbox_id nullable, message_id, from_address, to_addresses,
cc_addresses, subject, text_body, html_body, markdown_body(v2.1.0:正文 Markdown,
入库时从 HTML/纯文本转换), raw_storage_key, size,
received_at, expires_at, created_at

Console 收到邮件后根据收件人/内容与自身配置关联 mailbox。

email_attachments

id, email_id, filename, content_type, size, storage_key, content_id

Webhook(三级:邮箱 -> 域名 -> 全局)

域名/邮箱行内配置(webhook_url / webhook_headers / webhook_key_enc), 全局配置存 settings.global_webhook;独立 webhooks 实体已移除。

webhook_deliveries: id, email_id, target_type(mailbox|domain|global),
url, headers, key_enc, status, attempt_count, next_retry_at, last_error, delivered_at, created_at

投递行在入队时冻结解析出的配置,重试不受后续配置变更影响。

oauth_connections

id, provider, account_id, encrypted_access_token, refresh_token, expires_at, created_at, updated_at

OAuth token 必须加密存储。所有 Email 必须有 expires_at,默认 retention 为 86400 秒。

worker_credentials

id, cloudflare_account_id, worker_id, secret_hash, secret_enc, secret_last4,
status(active | revoked), created_at, revoked_at

用于 Email Worker 与 Console 内部认证:secret_hash 为摘要,secret_enc 为 AES-GCM 密文 (HMAC 验签需要原文,加密存储防拖库泄露);明文 secret 仅在签发/轮换时返回一次。

其它

users、settings(全局 Webhook、单一 API/MCP Key:api_key_hash/api_key_last4/api_key_created_at)、nonces、oauth_states、cf_sim_resources(本地 sim)。v2.1.0 起 api_credentials 表已删除(Key 合并为单一 Key 存 settings)。