23 Commits

Author SHA1 Message Date
xfy
2fba43dc3f chore(infra): add bollard dependency and modular structure 2026-07-03 17:49:08 +08:00
xfy
ff2694c5a3 feat(image): make size/pixel limits configurable, double defaults
Some checks failed
CI / check (push) Failing after 6m23s
CI / build (push) Has been skipped
将 MAX_IMAGE_DIMENSION / MAX_IMAGE_PIXELS 从编译期 const 改为运行时
LazyLock(启动读环境变量),默认值 x2。

- 默认值:单边 4096→8192,总像素 25M→50M
- clamp 策略:只设下限防危险小值(DIMENSION≥512,PIXELS≥1M),
  超下限 clamp + warn;无上限,完全信任运维
- 内存影响:默认 50M 像素对应 ~200MB/图解码缓冲(max_alloc)
- 模式复用 WEBP_CONFIG:env→parse→(val,clamped)→clamp→warn→info
- 所有引用点解引用(*MAX_...),含 upload.rs/webp.rs 跨文件
- check_upload_dimensions 超限文案改为动态读取上限,不再硬编码数值
- 测试改用 *MAX_IMAGE_DIMENSION+1,数值无关

.env.example 与 AGENTS.md 同步更新环境变量说明。
2026-06-24 13:54:36 +08:00
xfy
933c7a8c93 docs(env): document hardcoded image upload size limits
本次上传尺寸统一为硬编码 const(非环境变量),但 .env.example 已有
记录硬编码默认值的体例(如图片缓存头)。补一段说明上限数值与超限行为,
便于部署者知晓 4096/25M 的存在及调整方式。
2026-06-24 13:26:11 +08:00
xfy
0413e539fe docs(env): document IMAGE_DIMENSIONS_CACHE_TTL_SECS 2026-06-22 18:01:31 +08:00
xfy
694e198331 docs(env): expand and correct .env.example comments
依据代码核对修正多处不准确/缺失的注释,纯文档改动,无行为变化。

修正的不准确项:
- RATE_LIMIT_STRICT_* 实际覆盖登录/注册/评论预检/搜索,原注释只写登录注册
- STATEMENT_TIMEOUT_SECS 是 Postgres 服务端取消(非客户端断连),仅经连接池的连接生效
- COMPRESSION_ALGORITHMS 示例值(四项全开)等价于 all,消除注释默认 vs 示例值的歧义

补全的缺失细节:
- RUST_LOG 补细粒度语法示例(info,yggdrasil=debug)
- 限流项统一说明 token bucket 模型(PER_SEC 稳态 / BURST 突发容量)
- MAX_SESSIONS_PER_USER 超限按最旧优先删除(LRU)
- DB_POOL_SIZE 与 Postgres max_connections 的关系
- WEBP_QUALITY/METHOD 越界会 clamp 不报错
- TRUSTED_PROXY_COUNT 设错的双向安全后果
- IMAGE_DISK_CACHE_* 清理任务每小时跑一次
- MIGRATE_STARTUP_TIMEOUT_SECS 500ms 固定间隔轮询
- SSR_CACHE_SECS 文章更新后最长滞后 TTL 秒可见
- APP_BASE_URL 反向代理后 Host 头可被影响的 CSRF 风险

结构上用分隔线分组(Rate Limit / Security / WebP / SSR / Image Cache),
安全注意事项用 ⚠️ 标记。
2026-06-22 13:32:49 +08:00
xfy
2c7319c220 docs(env): translate .env.example comments to Chinese
纯文档翻译,无行为变化。把英文注释全部译为中文,保持原有中文注释
(限流段)和变量名、默认值、文件结构不变。
2026-06-22 13:20:31 +08:00
xfy
a3ed0a2b4e docs(env): document RATE_LIMIT_COMMENT_* and RATE_LIMIT_UNKNOWN_* vars
rate_limit.rs registers four limiters (strict/upload/image/comment) plus
an "unknown" fallback bucket for when the real client IP can't be
determined, but only the strict/upload/image tiers were listed in
.env.example and AGENTS.md. Add the missing comment and unknown tier
tunables so the documented surface matches the code.
2026-06-22 13:16:34 +08:00
xfy
b24cfdcabc fix(startup): replace migration panic with friendly exit + configurable retry window
DB migration failure at startup panicked via .expect() (main.rs:223),
dumping a raw backtrace for what is usually just "PostgreSQL isn't running
yet". Worse, the 1.6s runtime retry budget was reused at startup, so it
almost always failed against a cold/slow DB (docker-compose without
healthchecks, local Postgres not started, etc.).

Changes:
- pool: extract build_pg_config() (returns Result, no panic); add
  validate_database_url() so URL-format / DB_POOL_SIZE errors surface as
  friendly exit(1) instead of hitting the LazyLock's unreachable .expect()
- pool: add get_conn_for_startup() — a startup-only retry loop with a
  configurable total-duration window (MIGRATE_STARTUP_TIMEOUT_SECS,
  default 30s, 500ms interval), separate from the runtime get_conn()
  anti-avalanche fast retry (untouched)
- migrate: split run() into run_on_conn(&mut conn) so callers control the
  connection-acquisition strategy; main.rs pairs this with the startup
  retry. Advisory-lock release comment updated: exit(1) terminates the
  process just like panic, so the session-level lock is still freed
- main: startup fatal errors (bad URL, DB unreachable, migration failed)
  now each emit tracing::error! + eprintln! ERROR + targeted HINT, then
  exit(1) — no panic, no backtrace nudge
- .env.example / AGENTS.md: document MIGRATE_STARTUP_TIMEOUT_SECS

No runtime behavior change: get_conn() and its ~40 call sites are
unchanged. Advisory-lock safety preserved (documented in migrate.rs).
2026-06-22 11:24:13 +08:00
xfy
790002181a docs(env): add APP_BASE_URL and other security vars to .env.example
Some checks failed
CI / check (push) Failing after 12m34s
CI / build (push) Has been skipped
Task 1.1 疏漏:只更新了 AGENTS.md,漏了 .env.example。补上本次 review 引入及
原先缺失的 security 变量:
- APP_BASE_URL(CSRF 校验的可信 origin,1.1 引入)
- STATEMENT_TIMEOUT_SECS(慢查询超时,2.4 引入)
- COOKIE_SECURE / TRUSTED_PROXY_COUNT(原先就缺,一并补全)
2026-06-18 14:24:09 +08:00
xfy
306da3cf83 Merge caching and SSR invalidation improvements
Some checks failed
CI / check (push) Failing after 24m9s
CI / build (push) Has been skipped
2026-06-18 10:43:40 +08:00
xfy
668920e9fb docs(ssr): clarify that generation counters are future-ready infrastructure 2026-06-18 10:30:18 +08:00
xfy
3ee39d910c refactor(ssr): remove unused per-slug/per-tag generation counters 2026-06-18 10:30:07 +08:00
xfy
f1e5b657a3 chore(env): document image disk cache limits in .env.example 2026-06-18 10:03:42 +08:00
xfy
05b9a3a595 feat: enable all HTTP compression algorithms by default
Some checks failed
CI / check (push) Failing after 14m38s
CI / build (push) Has been skipped
- COMPRESSION_ALGORITHMS defaults to 'all' when unset

- Support 'none'/'off' to explicitly disable compression

- Add parse_compression_algorithms helper and unit tests

- Update .env.example comment to reflect new default
2026-06-17 17:03:17 +08:00
xfy
facb75d632 feat: make HTTP compression algorithms configurable via COMPRESSION_ALGORITHMS
Some checks failed
CI / check (push) Failing after 6m57s
CI / build (push) Has been skipped
2026-06-17 16:38:41 +08:00
xfy
2d45e0991b docs: clarify image cache invalidation behavior 2026-06-17 14:22:20 +08:00
xfy
dc7eb77fad docs: document image cache-control defaults 2026-06-17 14:19:42 +08:00
xfy
bd9e87128d perf(ssr): optimize request throughput by 32%
- Cache ammonia::Builder with LazyLock (was rebuilt per request)
- Enable tracing release_max_level_info to strip tracing overhead at compile time
- Remove TraceLayer and tower-http trace feature from production
- Increase DB pool size 10→20 (configurable via DB_POOL_SIZE)
- Increase SSR cache TTL 300s→3600s (configurable via SSR_CACHE_SECS)

Benchmark: 7,444 → 9,840 req/s, P99 latency 27.6ms → 11.1ms
2026-06-12 09:36:53 +08:00
xfy
ccd564312b feat: hash session tokens and enforce configurable session limit per user 2026-06-11 09:45:56 +08:00
xfy
2e2be7b16d feat: add WebP encoding support with zenwebp
- Replace image crate's WebP with zenwebp for better quality/speed
- Add webp.rs module with configurable quality and method
- Update .env.example with WEBP_QUALITY and WEBP_METHOD
- Add WebP decode support in image serving pipeline
- Add detailed timing logs for WebP conversion
2026-06-09 15:30:06 +08:00
xfy
3974856f3d fix: resolve image/upload 500 errors and refactor rate limiting
- Separate /uploads and /api/upload routes from Dioxus app to avoid
  IncrementalRenderer intercepting non-page requests
- Remove broken SmartIpKeyExtractor-based general_limit() that failed
  under Dioxus dev server proxy (Unable To Extract Key)
- Move rate limiting into handlers using governor::RateLimiter directly
- Add IMAGE_LIMITER for /uploads/* serving
- Make all rate limits configurable via environment variables
- Add rate limit config to .env.example with sensible defaults
2026-06-09 09:48:51 +08:00
李林军
4093178fc3 添加tracing日志并重构服务器启动逻辑 2026-05-27 11:39:09 +08:00
xfy
8b9c6aa83d 重构 admin 模块,新增共享组件和文章撰写页面
- 将 monolithic admin.rs 拆分为 admin/ 目录模块(dashboard、write)
- 新增 components 模块:Header、Footer、AdminLayout
- 新增 /admin/write 文章撰写页面,支持 Markdown 实时预览
- 添加 pulldown-cmark 依赖用于 Markdown 渲染
- .env 移出版本控制,新增 .env.example 模板
- Home、Archives、Tags、Login、Register 等页面适配新组件

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