16 Commits

Author SHA1 Message Date
xfy
449a545886 security: fix critical issues from repository review
Some checks failed
CI / build (push) Has been cancelled
CI / check (push) Has been cancelled
P0 blockers:
- Fix migration numbering conflict and duplicate indexes
- Change comments.post_id FK to ON DELETE CASCADE
- Restrict public post detail endpoint to published posts only
- Fix rate-limiting IP extraction and fallback to ConnectInfo
- Harden HTML sanitizer: deny unknown URL schemes, restrict data URIs
- Remove session token from login response body
- Enforce image pixel/dimension limits on upload and serving

P1 high-risk:
- Validate uploads by magic bytes and decode GIF/WebP
- Add pagination/rate-limiting to search, tag posts, and comments
- Make first-admin registration and slug uniqueness check atomic
- HTML-escape comment author fields
- Improve HTML minify cache key and skip admin/error responses
- Add mobile navigation menu

P2 accessibility/quality:
- Associate form labels with inputs
- Key PostDetail article by slug to re-init scripts on navigation
- Improve image viewer keyboard accessibility
- Make theme toggle SSR-friendly and add aria-label
- Invalidate slug 404 cache on create and pending count on new comment
- Deduplicate tags case-insensitively

P3 cleanup:
- Remove unused tower-http dependency, expand make clean
- Configure DB pool timeouts and verified recycling
- Run background cleanup tasks immediately on startup
- Use SHA-256 for stable disk cache keys
- Log DB errors with Display instead of Debug
- Update README migration instructions

All tests pass (321), clippy clean, dx check clean.
2026-06-17 10:34:14 +08:00
xfy
cafbddb861 refactor: replace server-only dead_code allows with cfg(feature = "server")
Replace #[allow(dead_code)] on server-only helpers with #[cfg(feature = "server")]
to make the server/WASM split explicit and avoid compiling unused server logic
into the WASM frontend.

- Gate password/session/auth/comment helpers and model parsers with server feature
- Gate related imports and tests accordingly
- Remove genuinely unused CreatePostRequest and CreateCommentRequest
- Keep #[allow(dead_code)] for true dead code (stub methods, unused public APIs)
- Use #[cfg(any(target_arch = "wasm32", test))] for THEME_KEY
- Update AGENTS.md note
2026-06-16 16:45:08 +08:00
xfy
19ffcada4a test: 移除脆弱断言与凑数测试(review 修正)
对本次新增测试自审后的清理:

1. webp: encode_lower_quality_produces_smaller_or_equal_bytes
   原断言“低质量体积 <= 高质量体积”是 WebP 的统计趋势而非
   确定性不变量,依赖底层 libwebp 量化策略,纯色图上高低差异
   接近 0,未来库升级易变为 flaky。改为验证两个质量档位都能
   成功编码并产生可被本模块解码的合法 WebP。

2. theme: theme_is_copy
   Copy 语义由编译器在编译期保证,运行期断言永真,不测任何
   运行逻辑,属凑数。

3. webp: webp_config_default_quality_and_method
   构造 struct 再断言字段等于构造时填入的值,是同义反复。

净减 2 个测试(292 → 290),全部通过。
2026-06-15 11:26:24 +08:00
xfy
4e89412cde test(theme): 扩充主题模块测试覆盖
原仅 2 个 toggle 测试,补充后覆盖:
- toggle 的对合性(连续切换两次回到原值)
- Theme 的 PartialEq / Copy trait 行为
- 首屏预加载脚本的关键行为契约:读取 localStorage、
  回退 prefers-color-scheme、添加 dark class、
  包裹 try/catch 防止禁用 localStorage 时抛错

共 9 个测试,全部通过。
2026-06-15 10:57:51 +08:00
xfy
1904907add docs(hooks, theme): 补充中文注释 2026-06-12 19:07:43 +08:00
xfy
4fe26f7eb3 test: improve unit test coverage and assertions
Some checks failed
CI / check (push) Failing after 15m51s
CI / build (push) Has been skipped
- Add tests for sanitizer, mime_to_ext, clean_tags, Theme::toggle
- Tighten assertions in highlight, markdown, post status classes
- Add boundary and XSS cases for comments, slug, rate_limit, webp
- Update Cargo.lock for serial_test dev-dependency
2026-06-12 18:13:51 +08:00
xfy
f9d23d1eed refactor(ui): redesign with warm palette, sage accent, and consistent theme vars
- Warm editorial color palette (#faf9f6 light / #141416 dark)
- Sage green accent (#5c7a5e) for nav, links, buttons, tags
- Replace all hardcoded hex colors with CSS theme utilities
- Serif font (system Georgia) only on header logo
- Better hover states: scale, brightness, color transitions
- Accent-colored focus rings on inputs
- Fix language mixing: Back to Home → 返回首页
- No external font dependencies
2026-06-11 10:29:11 +08:00
xfy
0a33a843f8 fix(theme): resolve hydration mismatch in ThemeToggle by deferring icon render until mounted 2026-06-05 17:07:23 +08:00
xfy
ccffab851a fix: admin pages use client-only fetching; fix theme cookie parsing; restore custom skeletons 2026-06-03 14:55:50 +08:00
xfy
6b3e086628 feat: read theme from cookie during SSR 2026-06-03 14:38:00 +08:00
xfy
61c1ec7282 修复暗色模式:class 变体、状态同步、FOUC 预防、系统偏好
- 配置 Tailwind v4 @custom-variant dark 使用 class 模式
- 用 use_context_provider 共享主题状态,修复 AppRouter/ThemeToggle 不同步
- 默认跟随系统偏好(matchMedia),无 localStorage 时自动检测
- 统一暗色标记为 .dark class,移除 data-theme 冗余
- ThemePreload 内联脚本在 DOM 解析前设置 class,消除首屏闪烁
- SVG 内联 + currentColor,图标颜色随主题切换
- Cargo.toml 补充 web-sys MediaQueryList/DomTokenList feature

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 11:31:06 +08:00
xfy
3079f1a505 ThemeToggle:用 SVG 图标替换 emoji,移除灰色背景
- 亮色模式使用太阳 SVG 图标
- 暗色模式使用月亮 SVG 图标
- 移除按钮的灰色背景,改为 hover 透明度变化

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 11:11:44 +08:00
xfy
8b3aab21de 恢复首页路由,添加归档/标签/搜索/关于路由占位
- router.rs: / 恢复为 HomePage,新增 /archives /tags /search /about
- mod.rs: 导出 home 模块
- theme.rs: ThemeToggle 从浮动按钮改为内联样式
- home.rs: 创建空占位文件

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 10:31:52 +08:00
xfy
5afd8b597c Fix clippy warnings
- Remove unnecessary clone on Copy type (navigator)
- Allow dead_code for THEME_KEY constant

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 16:51:12 +08:00
xfy
14b92c3a89 US-005: 后台页面与路由整合
- src/router.rs: Dioxus 路由定义 (/login, /register, /admin, /)
- src/main.rs: 整合所有模块 + server block 启动 dotenvy + session 清理任务
- src/tasks/session_cleanup.rs: 每小时清理过期 session
- 修复编译错误: chrono serde, tokio-postgres chrono, argon2 OsRng
- 移除 server_context 依赖,简化 get_current_user 查询
- Tailwind CSS CDN + darkMode class 配置

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 16:29:50 +08:00
xfy
4a77f2c457 US-004: 前端页面 - 注册与登录
- src/pages/register.rs: 注册表单 + 前端验证 + 错误提示
- src/pages/login.rs: 登录表单 + cookie 设置 + 跳转
- src/pages/admin.rs: 认证检查 + 欢迎信息 + 登出
- src/theme.rs: 暗色/亮色主题切换 + localStorage 持久化
- Tailwind CSS CDN + dark: modifier 实现主题

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 16:24:05 +08:00