Skip to content

修复HTTP 500#9

Open
xingxinag wants to merge 11 commits into
afoim:mainfrom
xingxinag:main
Open

修复HTTP 500#9
xingxinag wants to merge 11 commits into
afoim:mainfrom
xingxinag:main

Conversation

@xingxinag

@xingxinag xingxinag commented Jan 29, 2026

Copy link
Copy Markdown

🚨 核心修复 (Bug Fixes)

  1. 修复 Android 端 "MissingPropertyException" 崩溃问题
    • 原因: Android 客户端在使用 Argon2id 算法时,强制要求服务器返回 Memory 和 Parallelism 参数。由于历史数据库缺失这些字段,服务器此前返回 null,导致客户端解析失败崩溃。
    • 修复:
      • 在 src/handlers/identity.rs 和 src/handlers/accounts.rs 中实现了智能回退逻辑。
      • 对于 Argon2id 用户 (KdfType=1),如果数据库中缺失参数,服务器现在会自动返回默认值(Memory: 64MB, Parallelism: 4),确保客户端能正常工作。
  2. 修复服务器 HTTP 500 内部错误 (BigInt Compatibility)
    • 原因: Rust 代码试图将 i64 (BigInt) 类型直接绑定到 Cloudflare D1 数据库查询中,D1 不支持 BigInt,导致 Worker 运行时崩溃。
    • 修复: 在 identity.rs (登录限流) 和 devices.rs (设备类型) 中,将所有 i64 类型显式转换为 f64 或 i32,确保与 D1 数据库完全兼容。
  3. 修复注册时的 "Silent Failure" (500 Error)
    • 原因: 数据库 UNIQUE 约束(如邮箱重复)触发时,原始代码粗暴地返回通用的数据库错误,导致客户端收到 500 错误且无明确提示。
    • 修复:
      • 在 register 函数中增加了主动邮箱检查。
      • 实现了细粒度的错误处理,现在邮箱重复会返回标准的 400 Bad Request 和明确的错误信息 "Email already registered"。
        ✨ 架构升级 (Architecture Improvements)
  4. 数据库架构升级 (Schema Migration)
    • 变更: 成功在远程生产数据库 users 表中添加了 kdf_memory 和 kdf_parallelism 字段。
    • 意义: 正式支持 Argon2id 算法的完整参数存储,解决了“只存算法不存参数”的历史遗留问题。
  5. 模型与逻辑同步
    • 更新了 User 和 RegisterRequest 模型,正式支持读写 KDF 参数。
    • 更新了 register (注册)、change_master_password (改密)、prelogin (预登录) 和 token (登录) 四大核心接口,确保数据流转的完整性。
  6. 错误处理系统重构
    • 引入了增强版的 AppError 枚举,支持区分 DatabaseConstraint (业务错误) 和 Database (系统错误)。
    • 增加了关键路径的详细日志记录(如登录响应的 JSON 结构),极大提升了未来的排查效率。
      🛡️ 代码质量与安全 (Code Quality)
  7. 编译修复: 修复了 query! 宏在处理 JsValue 序列化时的编译错误,优化了代码写法。
  8. 安全审计: 全面审查了代码库,确认移除了潜在的 unwrap() 崩溃风险,并验证了 SQL 注入防护措施

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.

1 participant