Skip to content

新增公开图库:创作者自愿申请、维护者用脚本审核后展示 - #48

Merged
mingzhangyang merged 10 commits into
mainfrom
claude/admiring-allen-ynn8rs
Nov 28, 2026
Merged

mingzhangyang merged 10 commits into
mainfrom
claude/admiring-allen-ynn8rs

Conversation

@mingzhangyang

@mingzhangyang mingzhangyang commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

概要

新增公开图库(/gallery),并让登录用户发布的分享归属到账号,可以在任何设备上管理。匿名发布保留,撤销密钥的提示被弱化;申请进入图库必须登录,所有投稿由维护者用脚本审核后才会展示。另外,桌面导航轨改为只显示图标,并在底部加入公开图库入口。

登录用户:分享归属账号

  • 发布流程本身保持匿名,原有协议(预存 ID 和密钥、幂等重试、确认、撤销)没有改动。登录状态下发布成功后,浏览器用已保存的撤销密钥证明所有权,调用 POST /api/me/shares/claim 把分享绑定到账号(新增字段 owner_user_id)。
  • “我的分享”和账户页新增“我的作品”,换设备也能查看、复制链接、无需密钥直接撤销、申请入库或撤出。
  • 当前浏览器里未登录时发布的作品,可以一键“并入我的账号”。已归属其他账号的作品会提示原因,之后不再反复提示并入。
  • 新增账号接口(均需 Clerk 登录):
    • GET /api/me/shares?cursor=&limit=:分页列出作品,默认 50 件、最多 100 件,返回 nextCursor
    • POST /api/me/shares/owned:按 ID 查询哪些分享属于当前账号,与当前显示哪一页无关
    • POST /api/me/shares/claim:用撤销密钥认领分享,每次最多 50 件;返回 claimed 和 ownedElsewhere(密钥匹配但已归属其他账号)
    • DELETE /api/me/shares/:id:撤销分享
    • PUT|DELETE /api/me/shares/:id/gallery:申请或撤出图库

匿名用户

  • 照常发布,在同一个浏览器里可以随时撤销。
  • “复制私人撤销密钥”收进了“备份撤销密钥(换设备时使用)”折叠项。提示文字改为“可以随时在此浏览器的‘我的分享’中撤销”,8 种语言同步修改。
  • 发布结果不确定、或本地无法保存密钥时,仍会直接显示密钥,这部分没有弱化。

公开图库

  • 发布对话框新增“同时申请展示到公开图库”,默认不勾选。只有登录用户、且有效期选择“永不过期”时才能勾选,服务器端同样会校验。
  • GET /api/gallery:分页列出已通过的作品,缩略图使用现有的 card.jpg。作品被撤销后会立即从图库消失。
  • 新增 /gallery 页面,桌面导航轨底部、设置面板和分享页底部都有入口。
  • 举报:分享页新增“举报这件作品”入口(POST /api/shares/:id/report),按网络限流,每位访客对同一作品只计一次。访客按 IPv4 地址或 IPv6 的 /64 网段计算;存储的举报者标识和限流键都是以 Worker 密钥 SHARE_REPORT_SECRET 为密钥的 HMAC,无法通过逐个试算地址还原 IP。
    • 已展示的作品收到 3 位不同访客的未处理举报后,会自动退回待审并从图库中隐藏,分享链接保留。
    • 是否“已处理”按审核代次判定:每次审核(通过、拒绝、下架、清除举报)都会在同一条 UPDATE 里把作品的代次加一;举报记录提交时的代次,两者相同即为未处理。由写入顺序决定,不受时间戳只精确到秒的影响。
    • 写入举报和检查阈值在同一个原子 D1 batch 中执行,并且每次举报都会重新检查,重复举报也能补完此前中断的隐藏操作。
    • 定时清理会删除已处理的举报、已撤销分享的举报,以及超过 90 天的未处理举报。

桌面导航轨:只显示图标

  • 导航轨上的文字标签改为屏幕阅读器文字,仍是标签页和标签面板的可访问名称。鼠标悬停或键盘聚焦时,在导航轨右侧显示完整标题提示(例如“尺寸”显示“画布尺寸”),提示浮在面板之上。导航轨宽度由 72px 收窄到 64px。
  • 导航轨底部新增公开图库链接,与上方标签用细线隔开。它会离开编辑器,所以放在标签列表之外,是普通链接而不是标签页,方向键导航不会经过它。手机端没有导航轨,入口仍在设置面板。

审核脚本

npm run gallery:review 通过 wrangler 直接读写 D1,不需要任何管理接口:

  • 逐条审核待审作品:打开作品页、通过、拒绝、跳过、彻底下架
  • pending / listed / reports / show:查看列表或单件作品
  • approve / reject / dismiss / remove:批量操作

脚本会显示每件投稿来自哪个账号及其邮箱,只通过属于账号的作品。打印前会去掉标题和作者中的终端控制字符。

部署前

  1. 设置举报用的 HMAC 密钥(至少 32 个字符)。未设置时举报返回 503,/api/health/sharing 报告 SHARE_REPORTS_UNCONFIGURED:
    openssl rand -hex 32 | npx wrangler secret put SHARE_REPORT_SECRET
  2. 执行数据库迁移:
    • 0007_share_gallery.sql:在 shared_artworks 上新增 gallery_* 字段和审核代次 gallery_review_generation,新建 share_reports 表(含 review_generation)
    • 0008_share_owners.sql:新增 owner_user_id 及索引
    npx wrangler d1 migrations apply DB --remote --config wrangler.jsonc

两个迁移都只新增、不修改已有结构。/api/health/sharing 的健康检查已覆盖新字段和新表,迁移未执行时会报告未就绪。

已处理的审查意见

  • 账号作品列表只返回最新 200 件:改为游标分页并加入“加载更多”。判断本地作品是否已并入账号改用 owned 接口,不再依赖当前显示的页。
  • approve 会误删新举报:审核时不再删除举报,approve 改为单条原子 UPDATE,只影响本次真正通过的作品。
  • 秒级时间戳无法区分审核与举报的先后:改用审核代次(字段在迁移 0007 中),测试中去掉了时间回拨,新增同一秒内“举报 → 审核 → 再举报”的顺序测试。
  • 举报阈值隐藏不是原子操作,重试也无法补救:举报写入与阈值检查合并为原子 batch,且每次举报都重新检查。新增回归测试:模拟举报已写入但未隐藏,同一访客重试后作品被正确隐藏。
  • 举报者标识可被反推、未处理举报永久保留:改用带密钥的 HMAC,并为未处理举报设 90 天保留期,隐私页同步更新。
  • IPv6 用户可轻易冒充多位访客:举报者标识和限流按 IPv6 /64 计算。
  • 换账号后“并入我的账号”无法完成且没有提示:认领接口返回 ownedElsewhere,浏览器记住并提示;既未并入也不属于他人的作品会重新检查状态。
  • 迁移 0009 的回填永远不会用到:0007、0008 尚未上线,审核代次字段并入 0007,删除 0009。

测试

  • 已合并最新 main(装饰可贴近画布边缘:按可见内容交互,留白只约束文字 #47),解决了 README 冲突。npm run verify 通过:前端单元测试 360 个,Worker 测试 72 个。
  • Worker 测试覆盖:图库与账号接口、205 件作品分页、跨页归属查询、已展示作品收到新举报、混合批量 approve、同一秒内的举报与审核顺序、中断后重试补完阈值、dismiss 与定时清理。审核脚本的 SQL 直接在迁移后的 D1 上执行测试。
  • Worker 测试另外覆盖:IPv6 /64 归并(阈值与限流)、HMAC 标识与缺少密钥时的 503、90 天保留期清理、ownedElsewhere 只在密钥匹配时返回。
  • Playwright:新增 public-gallery.spec.ts,覆盖匿名发布、登录发布并入库、加载更多、并入账号和图库页面,以及“作品归属其他账号时,认领一次后不再提示”。
  • Playwright(导航轨):sidebar-navigation.spec.ts 新增两个用例:标签文字不占可见空间、悬停和键盘聚焦都显示完整标题且提示浮在面板之上;图库链接在标签列表之外、位于设置下方并能打开 /gallery。sidebar-navigation、public-gallery、share-links、editor-draft-safety、custom-template-save-navigation、seal-* 合计 102 个通过,26 个手机端重复用例按设计跳过。
  • 手动验证:在本地运行 Worker,走完“发布并申请入库 → 脚本通过 → /gallery 展示 → 举报”的完整流程,并在桌面、412 px 和 360 px 宽度下截图检查。审核脚本也在本地 D1 上跑过。导航轨在 1280 px 宽度下用英文和中文截图检查。

文档

docs/shareable-artwork-links.md(含图库入口位置)、docs/operations-runbook.md(新增“Public gallery review”一节)、README 和隐私政策页均已同步更新。

🤖 Generated with Claude Code

https://claude.ai/code/session_01FspVTmN6NY7LBGQ6yRxtSP
https://claude.ai/code/session_01FspVTnR4EfSetCMXy2wz6z

- 发布对话框新增“同时申请展示到公开图库”,仅“永不过期”的分享可勾选;
  “我的分享”里可查看图库状态、申请或撤出。
- Worker 新增 GET|PUT|DELETE /api/shares/:id/gallery(凭私人撤销密钥)、
  GET /api/gallery(分页列出已通过作品)和 POST /api/shares/:id/report。
  撤销分享会立即从图库消失;同一已展示作品被 3 位不同访客举报后自动退回待审。
- 迁移 0007:shared_artworks 增加 gallery_* 字段,新建 share_reports;
  健康检查覆盖新表和新字段,定时任务清理已撤销分享的举报。
- 新增 /gallery 页面、分享页举报入口、设置面板入口,文案覆盖 8 种语言。
- 新增 scripts/gallery-review.mjs(npm run gallery:review):通过 wrangler
  直接在 D1 上逐条审核、通过、拒绝、清除举报或彻底下架,无需管理接口。
- 文档:分享文档、运维手册、README 和隐私政策同步更新。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FspVTmN6NY7LBGQ6yRxtSP
- 发布流程保持匿名不变。登录状态下发布成功后,浏览器用已保存的撤销密钥
  证明所有权,调用 POST /api/me/shares/claim 把分享绑定到账号
  (迁移 0008 新增 owner_user_id)。
- 新增账号接口:GET /api/me/shares 列出作品,DELETE /api/me/shares/:id
  无需密钥即可撤销,PUT|DELETE /api/me/shares/:id/gallery 申请或撤出图库。
  原先凭密钥操作图库的 /api/shares/:id/gallery 已移除。
- “我的分享”和账户页新增“我的作品”,换设备也能查看和撤销;当前浏览器里
  未登录时发布的作品可一键并入账号。
- 申请入库必须登录;审核脚本显示提交账号和邮箱,只通过属于账号的作品。
- 匿名用户的撤销密钥备份按钮收进“备份撤销密钥”折叠项,相关提示改为
  “可随时在此浏览器撤销”,8 种语言同步。
- 文档、运维手册、README 和隐私政策同步更新。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FspVTmN6NY7LBGQ6yRxtSP

@mingzhangyang mingzhangyang left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPR review — HEAD 7c496fb

Scope: Initial targeted audit of the gallery/ownership APIs, account and publish UI, visitor-report lifecycle, D1 migrations, moderation SQL/CLI, docs and relevant test coverage.
Findings: 0 P0, 0 P1, 3 P2, 0 P3. Two findings are inline; the third is below.

[P2] Make the report threshold transition atomic or repairable on retry — worker/gallery.ts, reportShare, if (inserted.meta.changes === 1). The INSERT commits separately from the status UPDATE. If the third distinct report is persisted but the UPDATE throws (or the invocation terminates), a retry from the same visitor gets zero inserted rows and skips the UPDATE, returning 202 while the artwork remains listed with three reports. Use an atomic D1 batch/trigger for insertion and conditional hide, or always re-evaluate the threshold on duplicate retries. Add a regression simulating persisted threshold reports with status still listed, then retrying an existing reporter.

Verification: Isolated local SQLite reproductions of the account list cap and no-op approval deleting reports both reproduced; simulated interrupted report write also reproduced the skipped hide on duplicate retry. These are SQL-level reproductions, not full D1/browser integration tests. No prior inline threads in the snapshot.
Limits: The local runtime could not resolve github.com for a checkout; npm run verify and browser tests were not run. Full 38-file coverage (including localization and complete CLI) is not verified. This is a partial comment review, not an approval. No CI triggered.

Comment thread worker/accountShares.ts Resolved
Comment thread scripts/gallery-review-sql.mjs Resolved
- /api/me/shares 改为游标分页(默认 50、最多 100 条,返回 nextCursor),
  列表新增“加载更多”,超过 200 件的作品也都能找到、撤销和撤出图库。
- 新增 POST /api/me/shares/owned,按 ID 查询哪些分享属于当前账号(不分状态),
  本地分享是否已并入账号不再依赖当前显示的那一页。
- 举报不再在审核时删除:通过、拒绝、下架或清除举报都会记录
  gallery_reviewed_at,之前的举报视为已处理,之后的仍有效。approve 成为
  单条原子 UPDATE,只影响本次真正通过的作品;对已展示作品重复执行 approve
  不会抹掉新举报。举报被处理过的访客可以再次举报。定时任务清理已处理的举报。
- 新增回归测试:205 件作品分页、跨页归属查询、已展示作品+新举报、
  混合批量 approve、dismiss 与清理。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FspVTmN6NY7LBGQ6yRxtSP

@mingzhangyang mingzhangyang left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPR incremental re-review: dc96d8b. Pagination and independent ownership lookup address the first thread; single conditional approve UPDATE addresses the no-op approval thread. Prior P2 remains: worker/gallery.ts reportShare still commits INSERT separately and gates the hide UPDATE on inserted.meta.changes === 1. Duplicate retry cannot repair an interrupted threshold transition. New P2 inline. Partial audit: full suite not independently run; prior full-file coverage incomplete. No CI triggered.

Comment thread scripts/gallery-review-sql.mjs Resolved
- 迁移 0009:shared_artworks 新增 gallery_review_generation,share_reports
  新增 review_generation。每次审核(通过、拒绝、下架、清除举报)在同一条
  UPDATE 中递增代次;举报记录提交时的代次,两者相等即为未处理。由写入顺序
  决定、不受秒级 CURRENT_TIMESTAMP 影响;迁移按原时间规则回填已处理的举报。
- 举报写入与阈值检查放进同一个原子 D1 batch,且每次举报都重新检查阈值,
  重复举报可补完此前中断的隐藏操作。
- 测试去掉时间回拨,新增同一秒内“举报→审核→再举报”的顺序测试、
  中断后重试补完阈值的回归测试,以及迁移 0009 回填的单元测试。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FspVTmN6NY7LBGQ6yRxtSP

@mingzhangyang mingzhangyang left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPR incremental re-review — ef44b10. Both outstanding P2 findings verified fixed by inspection: report insertion and unconditional threshold check now share an atomic D1 batch; generation-based review ordering is consistent across moderation SQL, upsert, threshold, maintenance and migration. Regression tests cover same-second ordering, duplicate retry repair and migration backfill. No new actionable findings in inspected delta (0 P0/P1/P2/P3). Prior pagination and no-op approval fixes remain intact. Partial review: repository-wide coverage and full test execution not independently verified; PR reports 349 frontend and 69 Worker tests passing. No CI triggered.

mingzhangyang and others added 4 commits November 27, 2026 18:16
- 举报者标识与举报限流键改为以 SHARE_REPORT_SECRET 为密钥的 HMAC-SHA-256;
  密钥缺失或短于 32 字符时举报返回 503,/api/health/sharing 报告
  SHARE_REPORTS_UNCONFIGURED
- IPv6 地址按 /64 计为同一访客,阈值与限流都按网络计算
- 定时清理删除超过 90 天的未处理举报;隐私页同步说明
- 认领接口返回 ownedElsewhere;浏览器记住已归属其他账号的作品,
  不再反复提示并入,并复查既未并入也不属于他人的作品状态
- 0007、0008 尚未上线,把审核代次字段并入 0007,删除 0009 及其回填测试

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 导航轨标签改为屏幕阅读器文字,仍作为标签页和标签面板的可访问名称;
  悬停或键盘聚焦时显示完整标题提示。导航轨宽度由 72px 收窄到 64px。
- 导航轨底部新增公开图库链接。它会离开编辑器,所以放在标签列表之外,
  是链接而不是标签页。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FspVTnR4EfSetCMXy2wz6z

@mingzhangyang mingzhangyang left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPR incremental re-review of HEAD 20de3a48 (previous ef44b10). The prior pagination/ownership, no-op approve, same-second generation ordering and interrupted threshold transition issues remain addressed by inspection. HMAC reporter IDs, IPv6 /64 grouping and retention cleanup are implemented; migration generation fields are now in 0007. Three existing inline threads are already resolved. Two new findings below (1 P2, 1 P3; no P0/P1). Partial review: the local runtime cannot resolve github.com, so no independent full suite/browser tests were run. PR description reports 360 frontend and 72 Worker tests passing; CI run 46084155743 was in progress when inspected. No CI triggered.

Comment thread src/sharing/PublishDialog.tsx Resolved
Comment thread src/sharing/PublishDialog.tsx Resolved

Copy link
Copy Markdown
Owner Author

Review findings repair report — code delivered; full validation pending

  • Original HEAD: 20de3a48cf84a1bdc58db66a95a86a5e46af9e3c
  • Verified PR HEAD: f8a38b47e752def037bbd35b01b13fc294f8ba83
  • P2 (4724475329): shared post-publication flow runs after successful recovery, retains original account/gallery intent, reports failure, and guards concurrent recovery/revoke.
  • P3 (4724475338): current-account ownership filtering and keyed account list preserve local revoke access across auth changes and failed lookups.
  • Changed files: PublishDialog.tsx and two new browser test/fixture files. Both review threads received replies; resolution left to reviewer.
  • Local checks: node --test logic-test.cjs (8/8 isolated mocked logic and syntax checks); patch application against pinned changed excerpts passed. These are not full project or real-browser tests.
  • Blocker: local checkout failed to resolve github.com; dependencies unavailable, so required npm run verify and new Playwright scenarios were not executed locally. Public repository normal CI allowed by the branch update; no manual dispatch or rerun. Full validation pending.

@mingzhangyang mingzhangyang left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incremental GPR re-review of f8a38b4: both previous findings are verified fixed. Recovery now completes the original account/gallery intent, with session checks and mutually guarded revoke/retry. Local ownership filtering is scoped to the active account, with keyed account list. Three new Playwright regressions cover recovery, account switch and failed ownership lookup/sign-out. No new actionable findings in the delta. Static review only; tests not independently executed, CI 46087486266 in progress. Prior full-audit limitations remain. No CI triggered.

Copy link
Copy Markdown
Owner Author

Fixed CI lint failure in abf6307: removed redundant initial assignment of linked in PublishDialog.tsx; both try/catch branches assign it before use. No behavior changes. Local lint could not run because checkout DNS resolution failed; normal CI on push is enabled.

@mingzhangyang
mingzhangyang merged commit e141536 into main Nov 28, 2026
2 checks passed
@mingzhangyang
mingzhangyang deleted the claude/admiring-allen-ynn8rs branch November 28, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants