28 Commits

Author SHA1 Message Date
xfy
fdf2243299 docs(env): 补全 .env.example 缺失的 5 个环境变量
代码中经 env::var 读取但示例文件遗漏:

- EXPOSE_VERSION_HEADERS (main.rs:232, 安全相关, 控制版本暴露响应头)
- SYSINFO_SAMPLE_SECS (sysinfo_sampler.rs:46, 后台采样间隔)
- CODE_RUNNER_MAX_SOURCE_BYTES (runner_config.rs:67)
- CODE_RUNNER_QUEUE_TIMEOUT_SECS (runner_config.rs:79)
- CODE_RUNNER_TASK_TTL_SECS (runner_config.rs:83)

默认值与代码一致, 注释风格沿用现有分组(安全段 / tuning 段 /
Code Runner 段)。交叉核对确认示例文件无多余项。
2026-07-16 11:42:30 +08:00
xfy
5b6cb7d796 feat(middleware): COMPRESSION_ALGORITHMS 默认值改为 off
未设置环境变量时不再默认启用全部压缩算法,改为默认关闭。显式设为
"all" 或具体算法组合仍可按需开启。

- src/middleware.rs: fallback 由 "all" 改为 "off",同步更新文档注释
  与默认值测试(compression_default_env_is_all → _is_off)
- .env.example: 示例值与说明同步更新
2026-07-16 11:33:14 +08:00
xfy
2f6f8e549d refactor(code-runner): default CODE_RUNNER_LANGUAGES to all-open
CODE_RUNNER_LANGUAGES 未设置时,白名单不再默认为 python,node,
而是放行 LANGUAGES 注册表里的全部语言。该环境变量变为「可选的收窄开关」:
新增语言到注册表即可默认启用,无需再同步运维白名单(避免两边脱节,
如本次 go/rust 就因 .env 未同步白名单导致 is_supported_lang 拒绝)。

- RunnerConfig.languages: Vec<String> → Option<Vec<String>>,
  None 表示不限制
- is_supported_lang: Option 为 None 时直接放行注册表语言
- 测试 is_supported_lang_default_whitelist → is_supported_lang_default_all_open,
  断言 go/rust 在默认(未设白名单)下可用
2026-07-09 11:02:04 +08:00
xfy
c624997c04 feat(code-runner): add Go and Rust language support
为 Code Runner 新增 Go 和 Rust 两种编译型语言,沿用现有 base 镜像分层结构。

Go:
- run_cmd 直接用 go run(单条命令,内部编译+运行)
- 镜像把 GOCACHE/GOTMPDIR/GOPATH 重定向到 /tmp tmpfs
  (只读根文件系统下 /Users/issuser/.cache 不可写)
- default_limits: 1 核 / 256MB / 10s(编译冷启动比解释型慢)

Rust:
- rustc 编译 + 运行是两步,但 docker.rs 注入脚本用 exec 执行 run_cmd,
  exec 替换 shell 进程后 'A && B' 后半段不执行,
  因此镜像内置 /usr/local/bin/run-rust.sh wrapper 封装两步
- default_limits: 1 核 / 512MB / 15s(rustc 内存大、编译慢)

新增镜像与白名单后,默认 CODE_RUNNER_LANGUAGES=python,node,go,rust。
2026-07-09 09:40:32 +08:00
xfy
9fe128d44d feat(api): implement StartExec and GetExecResult server functions
- rate_limit.rs: 新增 CODE_EXEC 双层限流(per-second burst + 每日总额)
  governor 0.8 无 per_day,用 with_period(24h)+allow_burst 模拟
- execute.rs: StartExec(IP 提取/语言白名单/源码大小/入队/并发信号量/clamp/容器执行)
  + GetExecResult(轮询读取 DashMap);系统异常脱敏,日志记详情
- .env.example: RATE_LIMIT_CODE_EXEC_PER_SEC 改为整数(governor 不支持小数)
2026-07-03 18:15:59 +08:00
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