571 Commits

Author SHA1 Message Date
xfy
b48590ced3 feat: add compression and timeout middleware, skip uploads and image routes 2026-06-17 13:45:55 +08:00
xfy
7bad3ce382 fix: make ConnectInfo optional in serve_image to prevent 500 2026-06-17 13:40:17 +08:00
xfy
28fd38e6b8 docs(plan): remove stale references to removed comment APIs 2026-06-17 13:11:53 +08:00
xfy
3df6633428 chore(deps): update Cargo.lock after removing http-body-util 2026-06-17 13:11:53 +08:00
xfy
48888a9886 feat(migrations): add cleanup migration for duplicate indexes 2026-06-17 13:11:53 +08:00
xfy
08895f504e refactor(migrations): remove duplicate idx_tags_name and idx_post_tags_tag_id 2026-06-17 13:11:53 +08:00
xfy
73aa680202 refactor(migrations): remove redundant idx_posts_slug index 2026-06-17 13:11:53 +08:00
xfy
36055f99fa chore(deps): remove unused http-body-util and tower-http dependencies 2026-06-17 13:11:52 +08:00
xfy
260b26c693 deps: add tower-http for compression, timeout, trace middleware 2026-06-17 13:03:59 +08:00
xfy
d1c9cea683 refactor(cache): remove unused per-post comment count cache 2026-06-17 11:52:57 +08:00
xfy
07cb0a5b0d refactor(comments): stop invalidating removed comment count cache in updates 2026-06-17 11:45:49 +08:00
xfy
a7fb8405c3 refactor(comments): stop invalidating removed comment count cache 2026-06-17 11:43:16 +08:00
xfy
a4954a6c1b refactor(comments): remove unused CommentCountResponse and PendingCommentsResponse 2026-06-17 11:39:12 +08:00
xfy
fc9fce1f4d refactor(comments): remove dead re-exports from comments module 2026-06-17 11:30:14 +08:00
xfy
472d8e91fa refactor(comments): remove unused get_comment_count server function 2026-06-17 11:26:50 +08:00
xfy
0545412cf3 refactor(comments): remove unused get_pending_comments server function 2026-06-17 11:23:00 +08:00
xfy
d826afbe15 fix(db): 为 deadpool-postgres 连接池指定 Tokio1 runtime
Some checks failed
CI / check (push) Failing after 6m5s
CI / build (push) Has been skipped
2026-06-17 11:07:23 +08:00
xfy
b045a1b978 fix build errors 2026-06-17 10:52:01 +08:00
xfy
2c1190d8fb 移除 SSR HTML minify 中间件及相关工具
Some checks failed
CI / check (push) Failing after 5m21s
CI / build (push) Has been skipped
2026-06-17 10:43:09 +08:00
xfy
476fad27e5 fix(minify): preserve Dioxus hydration markers and remove unsafe per-URL cache
- Keep Dioxus SSR comments (<!--#-->, <!--node-id<N>-->, <!--placeholder-->)

  during HTML minification to avoid hydration failures.

- Drop the per-URL minify cache in the Axum middleware: the same URL can

  render differently for logged-in vs anonymous users, so URL-level caching

  risks leaking admin UI into public responses.

- Let the middleware handle HTML minification once instead of minifying in

  markdown rendering as well.

- Consolidate CSS comment stripping into the existing minify_css path and

  add a benchmark for html_minify.
2026-06-17 10:43:09 +08:00
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
bd659c5b4f perf: add HTML/CSS minification for SSR responses and highlight CSS
Some checks failed
CI / check (push) Failing after 5m54s
CI / build (push) Has been skipped
- Add lol_html-based HTML whitespace minifier (utils/html_minify.rs)
  that collapses whitespace and strips comments while preserving
  <pre>, <code>, <textarea>, <script>, <style> content
- Add Axum middleware (middleware/minify_html.rs) that minifies
  text/html responses with per-URL moka cache (256 entries, 300s TTL)
- Wire middleware into the server router in main.rs
- Add CSS minifier to generate_highlight_css build step
- Apply minify_html to rendered markdown output and TOC
- Add http-body-util dependency for body collection in middleware
2026-06-17 09:49:44 +08:00
xfy
ae84c37f21 build: add Dockerfile and .dockerignore for static musl image
Some checks failed
CI / build (push) Has been cancelled
CI / check (push) Has been cancelled
- Multi-stage build using rust:1.96-bookworm builder and scratch runtime.
- Produces a fully statically linked x86_64-unknown-linux-musl server binary.
- Builds frontend assets (Tiptap, Tailwind, Dioxus WASM) and bundles public/.
- Image size ~25 MB; server listens on 0.0.0.0:3000.
2026-06-17 09:48:12 +08:00
xfy
56adbcf227 build: strip symbols from release binaries
Some checks failed
CI / check (push) Failing after 6m6s
CI / build (push) Has been skipped
2026-06-16 17:53:05 +08:00
xfy
0159b2321a fix(build): make build-linux produce a statically linked musl binary
- Work around Dioxus 0.7.9 leaking getrandom_backend=wasm_js cfg into
  the musl server build by disabling DX's auto flag and setting it only
  for wasm32 in .cargo/config.toml.
- Split build-linux into @client and @server steps so the server build
  can explicitly enable the server feature and target
  x86_64-unknown-linux-musl.
- Configure the musl linker to use x86_64-linux-musl-gcc.
2026-06-16 17:53:05 +08:00
xfy
2caca3a48d fix(dead_code): 清理假阳性与真死代码
Some checks failed
CI / build (push) Has been cancelled
CI / check (push) Has been cancelled
- settings.rs: retention 常量与 clamp_retention 仅服务端使用,加 #[cfg(feature = "server")]
- comment.rs: 删除未使用的 Comment 结构体
- cache.rs: 删除未使用的 invalidate_all_comment_caches 及其测试

验证: cargo check (server/wasm), cargo test (311 passed), dx check, cargo clippy
2026-06-16 17:48:47 +08:00
xfy
7d713cabc2 docs: document server-only optional dependencies in AGENTS.md
Some checks failed
CI / check (push) Failing after 5m15s
CI / build (push) Has been skipped
2026-06-16 17:32:04 +08:00
xfy
1a56c0cd3f test: gate AppError helper tests behind server feature
Some checks failed
CI / build (push) Has been cancelled
CI / check (push) Has been cancelled
2026-06-16 17:28:43 +08:00
xfy
a06e4a5b9d build: remove uuid js feature and commit Cargo.lock updates 2026-06-16 17:21:22 +08:00
xfy
2dcd300930 build: allow dead_code on CommentCountResponse for WASM builds 2026-06-16 17:12:35 +08:00
xfy
1444ccef86 build: make sha2 and hex optional and gated by server feature 2026-06-16 17:11:15 +08:00
xfy
fa5216c6c5 build: make http optional and gated by server feature 2026-06-16 17:10:52 +08:00
xfy
d246adbb32 build: make rand optional and remove explicit getrandom dependency 2026-06-16 17:10:27 +08:00
xfy
726c6ec4e5 build: make pulldown-cmark optional and gated by server feature 2026-06-16 17:09:39 +08:00
xfy
6489ac604e build: make regex optional and gated by server feature 2026-06-16 17:09:16 +08:00
xfy
837f120621 build: make uuid optional and gated by server feature 2026-06-16 17:08:48 +08:00
xfy
6a98e8767d build: make argon2 optional and gated by server feature 2026-06-16 17:08:19 +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
b7afd12538 fix(highlight): 大小写不敏感的语法名称匹配,修复 haskell 等高亮失效
Some checks failed
CI / check (push) Failing after 25m52s
CI / build (push) Has been skipped
2026-06-16 16:20:21 +08:00
xfy
6ce8915e6c fix(editor): 修复 focus() 把源码视图滚动到底部
切换到源码模式时 sourceTextarea.focus() 会触发浏览器将光标
所在行滚动进可视区域,光标默认在内容末尾,导致 textarea 被
拉到底部覆盖已设的滚动位置。改为 focus 后立即恢复 scrollTop。

同时移除调试日志。
2026-06-16 16:13:46 +08:00
xfy
ae6d80c9cc fix(editor): 修复滚动比例同步失效导致切换到底部
原 syncScrollRatio 封装在 display:'none' 之后重复读取源容器
scrollTop,此时浏览器已将其归零,导致比例计算为 0。改为提前
读取比例并直接应用,移除二次封装与调试日志。
2026-06-16 15:58:50 +08:00
xfy
914f168551 fix(editor): 切换视图时按滚动比例同步位置
修复切回富文本时编辑器滚动到底部的问题:移除 commands.focus()
(会强制滚动到光标位置),改用滚动比例跨模式同步,富文本与源码
视图按相同比例定位,保持视觉位置一致。
2026-06-16 15:53:28 +08:00
xfy
480aa92bb4 feat(editor): 新增 Markdown 源码视图切换
在 Tiptap 编辑器右上角增加 </> 悬浮按钮,支持在富文本与
Markdown 源码视图间双向切换,内容自动同步。getMarkdown() 在
源码模式下返回 textarea 内容,使 Rust 端提交逻辑无需改动。
2026-06-16 15:50:09 +08:00
xfy
c6d27f0ae0 feat(highlight): 新增 JSX 与 TSX 语法高亮
新建 syntaxes/JSX.sublime-syntax(纯 JS + JSX)与
syntaxes/TSX.sublime-syntax(TypeScript + JSX),两者共享同一套
JSX 规则:标签名(区分大写组件/小写 HTML 标签)、属性名、属性值
(字符串与 {expr} 表达式)、自闭合 />、闭合标签、嵌套子标签与
JSX 片段 <>...</>。

从 TypeScript.sublime-syntax 移除 tsx 扩展名:此前 tsx 命中的是
没有 JSX 支持的 TS 语法,遮蔽了新建的 TSX 语法。

新增回归测试覆盖 jsx/tsx 的标签名与属性名识别。
2026-06-16 15:45:38 +08:00
xfy
d549f4a476 feat(highlight): 新增 TypeScript 语法高亮
新增 syntaxes/TypeScript.sublime-syntax,覆盖声明/控制流关键字、
interface/type/enum 类型声明、函数声明与箭头函数、装饰器、原始类型
与标准库类型、访问修饰符、模板字符串(含 ${} 插值)、各类数字字面量。

同时修复别名表:移除旧的 ts/typescript/tsx -> js 降级映射。这些别名
在没有 TS 语法时是临时降级方案,但 find_syntax 按扩展名->名字->别名
顺序匹配,别名会抢先于扩展名命中内置 JS,导致新增的 TS 语法被永久
遮蔽(诊断输出为 source js 而非 source ts)。改为映射 typescript -> ts
扩展名,使其正确走自定义 TypeScript 语法。

新增两个回归测试覆盖关键字/类型高亮与别名解析。
2026-06-16 15:35:44 +08:00
xfy
61a001c03b feat(highlight): 新增 Zig 语法高亮
新增 syntaxes/Zig.sublime-syntax,覆盖声明/控制流关键字、函数声明、
内建函数(@import 等)、整数/浮点类型(含任意位宽 i0..i65535)、
标准库类型、字符串(含 {d} 格式化插值与多行字符串)、十六进制/八进制/
二进制数字、注释与文档注释、标签等。

新增两个回归测试覆盖关键字/函数/类型/字符串/数字高亮。
2026-06-16 15:25:11 +08:00
xfy
a9f0e8d16b docs(development): 补充代码高亮开发文档
- DEVELOPMENT.md 增加代码高亮系统的详细开发指南,
  涵盖添加/修复语法、刷新文章、调试流程等
- admin/posts.rs 重构重建逻辑:提取 do_rebuild 闭包消除重复,
  新增「重建全部」按钮用于批量刷新已有文章渲染缓存
2026-06-16 15:19:45 +08:00
xfy
e8be1967db fix(highlight): 语法加载改用编译期绝对路径并增加诊断日志
add_from_folder 之前用相对路径 syntaxes/,依赖运行时工作目录,
在 dx serve 启动的 server 子进程下可能解析失败导致自定义语法
(含 Swift)静默不加载。

改用 CARGO_MANIFEST_DIR 在编译期固化为绝对路径,消除工作目录
依赖;并在 LazyLock 初始化时输出加载路径、语法总数与 Swift 是否
命中,便于排查加载问题。
2026-06-16 14:49:44 +08:00
xfy
603a7f68cb refactor(ui): 提取共享 UI 组件,消除跨页面重复
新增 src/components/ui.rs 作为通用 UI 原子层,封装:

组件:
- <Pagination variant="admin"|"frontend">:合并 posts/comments/trash/home
  四个重复的分页实现,用 variant 区分配色(admin 灰黑 / 前台主题绿)
- <StatusBadge>:统一文章状态、评论状态、回收站剩余天数的徽章外层
- <EmptyState variant="default"|"error">:统一列表空态与加载失败占位

类名常量:
- ADMIN_CARD_CLASS / ADMIN_TABLE_CLASS / ADMIN_ROW_HOVER / CHECKBOX_CLASS
- BTN_SOLID_{GREEN,AMBER,RED}:批量操作实心按钮
- BTN_TEXT_{GREEN,AMBER,RED,ACCENT}:行内文字按钮

清理:
- 删除 input.css 中零引用的 .btn-primary 死代码(22 行)
- 删除 4 个重复的分页组件函数

注意:
- 前台空状态(home/search/archives/tags)保持 text-paper-secondary 配色,
  未强行统一到 admin 的灰色 token,避免改变视觉
- 回收站分页计数单位从"条"修正为"篇"(回收站里是文章)
2026-06-16 14:20:05 +08:00
xfy
188e607ec2 fix(highlight): 补全 Swift 语法高亮
Swift.sublime-syntax 之前是残缺定义,expression 上下文仅包含
空白/字符串/数字,导致关键字、类型、函数等全部无法高亮。

补全声明关键字(import/func/class/let 等)、控制流(if/return/
async/await)、标准库类型(Int/String/Array)、函数声明与调用、
属性(@objc)等上下文,并调整 include 顺序使函数声明名优先于
函数调用识别。

新增两个回归测试覆盖关键字/函数/类型/字符串高亮。
2026-06-16 14:17:17 +08:00