1. 05 Apr, 2026 2 commits
  2. 19 Mar, 2026 1 commit
    • QTom's avatar
      feat(admin): 用户管理新增分组列、分组筛选与专属分组一键替换 · ba7d2aec
      QTom authored
      - 新增分组列:展示用户的专属/公开分组,支持 hover 查看详情
      - 新增分组筛选:下拉选择或模糊搜索分组名过滤用户
      - 专属分组替换:点击专属分组弹出操作菜单,选择目标分组后
        自动授予新分组权限、迁移绑定的 Key、移除旧分组权限
      - 后端新增 POST /admin/users/:id/replace-group 端点,事务内
        完成分组替换并失效认证缓存
      ba7d2aec
  3. 04 Mar, 2026 2 commits
  4. 28 Feb, 2026 1 commit
  5. 23 Feb, 2026 1 commit
  6. 08 Feb, 2026 1 commit
    • shaw's avatar
      feat(ui): 用户列表页显示当前并发数 · e4d74ae1
      shaw authored
      优化 /admin/users 页面的并发数列,显示「当前/最大」格式,
      参考 AccountCapacityCell 的设计风格。
      
      - 后端 UserHandler 注入 ConcurrencyService,批量查询用户当前并发数
      - 新增 UserConcurrencyCell 组件,支持颜色状态(空闲灰/使用中黄/满载红)
      - 前端 AdminUser 类型添加 current_concurrency 字段
      e4d74ae1
  7. 07 Feb, 2026 1 commit
    • yangjianbo's avatar
      fix(audit): 第二批审计修复 — P0 生产 Bug、安全加固、性能优化、缓存一致性、代码质量 · 2588fa6a
      yangjianbo authored
      
      
      基于 backend-code-audit 审计报告,修复剩余 P0/P1/P2 共 34 项问题:
      
      P0 生产 Bug:
      - 修复 time.Since(time.Now()) 计时逻辑错误 (P0-03)
      - generateRandomID 改用 crypto/rand 替代固定索引 (P0-04)
      - IncrementQuotaUsed 重写为 Ent 原子操作消除 TOCTOU 竞态 (P0-05)
      
      安全加固:
      - gateway/openai handler 错误响应替换为泛化消息,防止内部信息泄露 (P1-14)
      - usage_log_repo dateFormat 参数改用白名单映射,防止 SQL 注入 (P1-16)
      - 默认配置安全加固:sslmode=prefer、response_headers=true、mode=release (P1-18/19, P2-15)
      
      性能优化:
      - gateway handler 循环内 defer 替换为显式 releaseWait 闭包 (P1-02)
      - group_repo/promo_code_repo Count 前 Clone 查询避免状态污染 (P1-03)
      - usage_log_repo 四个查询添加 LIMIT 10000 防止 OOM (P1-07)
      - GetBatchUsageStats 添加时间范围参数,默认最近 30 天 (P1-10)
      - ip.go CIDR 预编译为包级变量 (P1-11)
      - BatchUpdateCredentials 重构为先验证后更新 (P1-13)
      
      缓存一致性:
      - billing_cache 添加 jitteredTTL 防止缓存雪崩 (P2-10)
      - DeductUserBalance/UpdateSubscriptionUsage 错误传播修复 (P2-12)
      - UserService.UpdateBalance 成功后异步失效 billingCache (P2-13)
      
      代码质量:
      - search 截断改为按 rune 处理,支持多字节字符 (P2-01)
      - TLS Handshake 改为 HandshakeContext 支持 context 取消 (P2-07)
      - CORS 预检添加 Access-Control-Max-Age: 86400 (P2-16)
      
      测试覆盖:
      - 新增 user_service_test.go(UpdateBalance 缓存失效 6 个用例)
      - 新增 batch_update_credentials_test.go(fail-fast + 类型验证 7 个用例)
      - 新增 response_transformer_test.go、ip_test.go、usage_log_repo_unit_test.go、search_truncate_test.go
      - 集成测试:IncrementQuotaUsed 并发测试、billing_cache 错误传播测试
      - config_test.go 补充 server.mode/sslmode 默认值断言
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      2588fa6a
  8. 05 Feb, 2026 1 commit
  9. 02 Feb, 2026 2 commits
    • bayma888's avatar
      feat(admin): add user balance/concurrency history modal · 606e29d3
      bayma888 authored
      - Add new API endpoint GET /admin/users/:id/balance-history with pagination and type filter
      - Add SumPositiveBalanceByUser for calculating total recharged amount
      - Create UserBalanceHistoryModal component with:
        - User info header (email, username, created_at, current balance, notes, total recharged)
        - Type filter dropdown (all/balance/admin_balance/concurrency/admin_concurrency/subscription)
        - Quick deposit/withdraw buttons
        - Paginated history list with icons and colored values
      - Add instant tooltip on balance column for better UX
      - Add z-index prop to BaseDialog for modal stacking control
      - Update i18n translations (zh/en)
      606e29d3
    • song's avatar
      merge upstream main · 0170d19f
      song authored
      0170d19f
  10. 19 Jan, 2026 1 commit
    • 墨颜's avatar
      fix(user): 普通用户接口不返回备注 · 00d9fbd2
      墨颜 authored
      - 用户侧 dto.User 移除 notes 字段,避免泄露管理员备注\n- 新增 dto.AdminUser 并调整 /admin/users 系列接口使用\n- 前端拆分 User/AdminUser,管理端用户页面使用 AdminUser\n- 更新契约测试:/api/v1/auth/me 响应不包含 notes
      00d9fbd2
  11. 09 Jan, 2026 1 commit
    • IanShaw027's avatar
      fix(admin): 代码审查修复 - 输入验证和测试完善 · 7c3d5cad
      IanShaw027 authored
      根据 Codex 代码审查报告,修复所有 P0 和 P1 优先级问题。
      
      ## P0 紧急修复
      
      ### 1. 修复集成测试编译错误
      - 更新 group_repo_integration_test.go 中所有 ListWithFilters 调用
      - 添加缺失的 search 参数(传入空字符串)
      - 修复 4 处旧签名调用,避免 CI 编译失败
      
      ### 2. 添加统一的 search 参数输入验证
      为所有 admin handler 添加一致的输入验证逻辑:
      - group_handler.go: 添加 TrimSpace + 长度限制
      - proxy_handler.go: 添加 TrimSpace + 长度限制
      - redeem_handler.go: 添加 TrimSpace + 长度限制
      - user_handler.go: 添加 TrimSpace + 长度限制
      
      验证规则:
      - TrimSpace() 去除首尾空格
      - 最大长度 100 字符(防止 DoS 攻击)
      - 超长输入自动截断
      
      ## P1 改进
      
      ### 3. 补充 search 功能的单元测试
      新增 admin_service_group_test.go 中的测试:
      - TestAdminService_ListGroups_WithSearch
        - search 参数正常传递到 repository 层
        - search 为空字符串时的行为
        - search 与其他过滤条件组合使用
      
      新增 admin_service_search_test.go 文件:
      - 为其他 admin API 添加 search 测试覆盖
      - 统一的测试模式和断言
      
      ### 4. 补充 search 功能的集成测试
      新增 group_repo_integration_test.go 测试场景:
      - TestListWithFilters_Search
        - 搜索 name 字段匹配
        - 搜索 description 字段匹配
        - 搜索不存在内容(返回空)
        - 大小写不敏感测试
        - 特殊字符转义测试(%、_)
        - 与其他过滤条件组合
      
      ## 测试结果
      
      -  编译检查通过
      -  单元测试全部通过 (3/3)
      -  集成测试编译通过
      -  所有 service 测试通过
      
      ## 影响范围
      
      修改文件: 8 个
      代码变更: +234 行 / -8 行
      
      ## 相关 Issue
      
      解决代码审查中的安全性和稳定性问题:
      - 防止 DoS 攻击(超长搜索字符串)
      - 修复测试编译错误(CI 阻塞问题)
      - 提升测试覆盖率
      7c3d5cad
  12. 04 Jan, 2026 1 commit
    • IanShaw027's avatar
      fix(lint): 修复所有 Go 命名规范问题 · a4953785
      IanShaw027 authored
      - 全局替换 ApiKey → APIKey(类型、字段、方法、变量)
      - 修复所有 initialism 命名(API, SMTP, HTML, URL 等)
      - 添加所有缺失的包注释
      - 修复导出符号的注释格式
      
      主要修改:
      - ApiKey → APIKey(所有出现的地方)
      - ApiKeyID → APIKeyID
      - ApiKeyIDs → APIKeyIDs
      - TestSmtpConnection → TestSMTPConnection
      - HtmlURL → HTMLURL
      - 添加 20+ 个包注释
      - 修复 10+ 个导出符号注释格式
      
      验证结果:
      - ✓ golangci-lint: 0 issues
      - ✓ 单元测试: 通过
      - ✓ 集成测试: 通过
      a4953785
  13. 03 Jan, 2026 1 commit
    • ianshaw's avatar
      chore: 更新依赖、配置和代码生成 · 112a2d08
      ianshaw authored
      主要更新:
      - 更新 go.mod/go.sum 依赖
      - 重新生成 Ent ORM 代码
      - 更新 Wire 依赖注入配置
      - 添加 docker-compose.override.yml 到 .gitignore
      - 更新 README 文档(Simple Mode 说明和已知问题)
      - 清理调试日志
      - 其他代码优化和格式修复
      112a2d08
  14. 02 Jan, 2026 1 commit
    • IanShaw's avatar
      运维监控系统安全加固和功能优化 (#21) · 45bd9ac7
      IanShaw authored
      * fix(ops): 修复运维监控系统的关键安全和稳定性问题
      
      ## 修复内容
      
      ### P0 严重问题
      1. **DNS Rebinding防护** (ops_alert_service.go)
         - 实现IP钉住机制防止验证后的DNS rebinding攻击
         - 自定义Transport.DialContext强制只允许拨号到验证过的公网IP
         - 扩展IP黑名单,包括云metadata地址(169.254.169.254)
         - 添加完整的单元测试覆盖
      
      2. **OpsAlertService生命周期管理** (wire.go)
         - 在ProvideOpsMetricsCollector中添加opsAlertService.Start()调用
         - 确保stopCtx正确初始化,避免nil指针问题
         - 实现防御式启动,保证服务启动顺序
      
      3. **数据库查询排序** (ops_repo.go)
         - 在ListRecentSystemMetrics中添加显式ORDER BY updated_at DESC, id DESC
         - 在GetLatestSystemMetric中添加排序保证
         - 避免数据库返回顺序不确定导致告警误判
      
      ### P1 重要问题
      4. **并发安全** (ops_metrics_collector.go)
         - 为lastGCPauseTotal字段添加sync.Mutex保护
         - 防止数据竞争
      
      5. **Goroutine泄漏** (ops_error_logger.go)
         - 实现worker pool模式限制并发goroutine数量
         - 使用256容量缓冲队列和10个固定worker
         - 非阻塞投递,队列满时丢弃任务
      
      6. **生命周期控制** (ops_alert_service.go)
         - 添加Start/Stop方法实现优雅关闭
         - 使用context控制goroutine生命周期
         - 实现WaitGroup等待后台任务完成
      
      7. **Webhook URL验证** (ops_alert_service.go)
         - 防止SSRF攻击:验证scheme、禁止内网IP
         - DNS解析验证,拒绝解析到私有IP的域名
         - 添加8个单元测试覆盖各种攻击场景
      
      8. **资源泄漏** (ops_repo.go)
         - 修复多处defer rows.Close()问题
         - 简化冗余的defer func()包装
      
      9. **HTTP超时控制** (ops_alert_service.go)
         - 创建带10秒超时的http.Client
         - 添加buildWebhookHTTPClient辅助函数
         - 防止HTTP请求无限期挂起
      
      10. **数据库查询优化** (ops_repo.go)
          - 将GetWindowStats的4次独立查询合并为1次CTE查询
          - 减少网络往返和表扫描次数
          - 显著提升性能
      
      11. **重试机制** (ops_alert_service.go)
          - 实现邮件发送重试:最多3次,指数退避(1s/2s/4s)
          - 添加webhook备用通道
          - 实现完整的错误处理和日志记录
      
      12. **魔法数字** (ops_repo.go, ops_metrics_collector.go)
          - 提取硬编码数字为有意义的常量
          - 提高代码可读性和可维护性
      
      ## 测试验证
      -  go test ./internal/service -tags opsalert_unit 通过
      -  所有webhook验证测试通过
      -  重试机制测试通过
      
      ## 影响范围
      - 运维监控系统安全性显著提升
      - 系统稳定性和性能优化
      - 无破坏性变更,向后兼容
      
      * feat(ops): 运维监控系统V2 - 完整实现
      
      ## 核心功能
      - 运维监控仪表盘V2(实时监控、历史趋势、告警管理)
      - WebSocket实时QPS/TPS监控(30s心跳,自动重连)
      - 系统指标采集(CPU、内存、延迟、错误率等)
      - 多维度统计分析(按provider、model、user等维度)
      - 告警规则管理(阈值配置、通知渠道)
      - 错误日志追踪(详细错误信息、堆栈跟踪)
      
      ## 数据库Schema (Migration 025)
      ### 扩展现有表
      - ops_system_metrics: 新增RED指标、错误分类、延迟指标、资源指标、业务指标
      - ops_alert_rules: 新增JSONB字段(dimension_filters, notify_channels, notify_config)
      
      ### 新增表
      - ops_dimension_stats: 多维度统计数据
      - ops_data_retention_config: 数据保留策略配置
      
      ### 新增视图和函数
      - ops_latest_metrics: 最新1分钟窗口指标(已修复字段名和window过滤)
      - ops_active_alerts: 当前活跃告警(已修复字段名和状态值)
      - calculate_health_score: 健康分数计算函数
      
      ## 一致性修复(98/100分)
      ### P0级别(阻塞Migration)
      -  修复ops_latest_metrics视图字段名(latency_p99→p99_latency_ms, cpu_usage→cpu_usage_percent)
      -  修复ops_active_alerts视图字段名(metric→metric_type, triggered_at→fired_at, trigger_value→metric_value, threshold→threshold_value)
      -  统一告警历史表名(删除ops_alert_history,使用ops_alert_events)
      -  统一API参数限制(ListMetricsHistory和ListErrorLogs的limit改为5000)
      
      ### P1级别(功能完整性)
      -  修复ops_latest_metrics视图未过滤window_minutes(添加WHERE m.window_minutes = 1)
      -  修复数据回填UPDATE逻辑(QPS计算改为request_count/(window_minutes*60.0))
      -  添加ops_alert_rules JSONB字段后端支持(Go结构体+序列化)
      
      ### P2级别(优化)
      -  前端WebSocket自动重连(指数退避1s→2s→4s→8s→16s,最大5次)
      -  后端WebSocket心跳检测(30s ping,60s pong超时)
      
      ## 技术实现
      ### 后端 (Go)
      - Handler层: ops_handler.go(REST API), ops_ws_handler.go(WebSocket)
      - Service层: ops_service.go(核心逻辑), ops_cache.go(缓存), ops_alerts.go(告警)
      - Repository层: ops_repo.go(数据访问), ops.go(模型定义)
      - 路由: admin.go(新增ops相关路由)
      - 依赖注入: wire_gen.go(自动生成)
      
      ### 前端 (Vue3 + TypeScript)
      - 组件: OpsDashboardV2.vue(仪表盘主组件)
      - API: ops.ts(REST API + WebSocket封装)
      - 路由: index.ts(新增/admin/ops路由)
      - 国际化: en.ts, zh.ts(中英文支持)
      
      ## 测试验证
      -  所有Go测试通过
      -  Migration可正常执行
      -  WebSocket连接稳定
      -  前后端数据结构对齐
      
      * refactor: 代码清理和测试优化
      
      ## 测试文件优化
      - 简化integration test fixtures和断言
      - 优化test helper函数
      - 统一测试数据格式
      
      ## 代码清理
      - 移除未使用的代码和注释
      - 简化concurrency_cache实现
      - 优化middleware错误处理
      
      ## 小修复
      - 修复gateway_handler和openai_gateway_handler的小问题
      - 统一代码风格和格式
      
      变更统计: 27个文件,292行新增,322行删除(净减少30行)
      
      * fix(ops): 运维监控系统安全加固和功能优化
      
      ## 安全增强
      - feat(security): WebSocket日志脱敏机制,防止token/api_key泄露
      - feat(security): X-Forwarded-Host白名单验证,防止CSRF绕过
      - feat(security): Origin策略配置化,支持strict/permissive模式
      - feat(auth): WebSocket认证支持query参数传递token
      
      ## 配置优化
      - feat(config): 支持环境变量配置代理信任和Origin策略
        - OPS_WS_TRUST_PROXY
        - OPS_WS_TRUSTED_PROXIES
        - OPS_WS_ORIGIN_POLICY
      - fix(ops): 错误日志查询限流从5000降至500,优化内存使用
      
      ## 架构改进
      - refactor(ops): 告警服务解耦,独立运行评估定时器
      - refactor(ops): OpsDashboard统一版本,移除V2分离
      
      ## 测试和文档
      - test(ops): 添加WebSocket安全验证单元测试(8个测试用例)
      - test(ops): 添加告警服务集成测试
      - docs(api): 更新API文档,标注限流变更
      - docs: 添加CHANGELOG记录breaking changes
      
      ## 修复文件
      Backend:
      - backend/internal/server/middleware/logger.go
      - backend/internal/handler/admin/ops_handler.go
      - backend/internal/handler/admin/ops_ws_handler.go
      - backend/internal/server/middleware/admin_auth.go
      - backend/internal/service/ops_alert_service.go
      - backend/internal/service/ops_metrics_collector.go
      - backend/internal/service/wire.go
      
      Frontend:
      - frontend/src/views/admin/ops/OpsDashboard.vue
      - frontend/src/router/index.ts
      - frontend/src/api/admin/ops.ts
      
      Tests:
      - backend/internal/handler/admin/ops_ws_handler_test.go (新增)
      - backend/internal/service/ops_alert_service_integration_test.go (新增)
      
      Docs:
      - CHANGELOG.md (新增)
      - docs/API-运维监控中心2.0.md (更新)
      
      * fix(migrations): 修复calculate_health_score函数类型匹配问题
      
      在ops_latest_metrics视图中添加显式类型转换,确保参数类型与函数签名匹配
      
      * fix(lint): 修复golangci-lint检查发现的所有问题
      
      - 将Redis依赖从service层移到repository层
      - 添加错误检查(WebSocket连接和读取超时)
      - 运行gofmt格式化代码
      - 添加nil指针检查
      - 删除未使用的alertService字段
      
      修复问题:
      - depguard: 3个(service层不应直接import redis)
      - errcheck: 3个(未检查错误返回值)
      - gofmt: 2个(代码格式问题)
      - staticcheck: 4个(nil指针解引用)
      - unused: 1个(未使用字段)
      
      代码统计:
      - 修改文件:11个
      - 删除代码:490行
      - 新增代码:105行
      - 净减少:385行
      45bd9ac7
  15. 01 Jan, 2026 1 commit
    • Edric Li's avatar
      refactor: migrate wechat to user attributes and enhance users list · 404bf0f8
      Edric Li authored
      Migrate the hardcoded wechat field to the new extensible user
      attributes system and improve the users management UI.
      
      Migration:
      - Add migration 019 to move wechat data to user_attribute_values
      - Remove wechat field from User entity, DTOs, and API contracts
      - Clean up wechat-related code from backend and frontend
      
      UsersView enhancements:
      - Add text labels to action buttons (Filter Settings, Column Settings,
        Attributes Config) for better UX
      - Change status column to show colored dot + Chinese text instead of
        English text
      - Add dynamic attribute columns support with batch loading
      - Add column visibility settings with localStorage persistence
      - Add filter settings modal for search and filter preferences
      - Update i18n translations
      
      🤖 Generated with [Claude Code](https://claude.com/claude-code
      
      )
      Co-Authored-By: default avatarClaude Opus 4.5 <noreply@anthropic.com>
      404bf0f8
  16. 26 Dec, 2025 1 commit
    • shaw's avatar
      fix: admin handlers 添加 DTO 转换修复 JSON 序列化 · 739d0ee6
      shaw authored
      修复 PR #36 合并后部分 admin handler 直接返回 service 层对象导致
      JSON 字段名为 PascalCase 而非期望的 snake_case 问题。
      
      修复内容:
      - account_handler: Refresh 接口添加 dto.AccountFromService
      - openai_oauth_handler: RefreshAccountToken/CreateAccountFromOAuth 添加 dto 转换
      - subscription_handler: BulkAssign 添加 dto.BulkAssignResultFromService
      - usage_handler: List 接口添加 dto.UsageLogFromService 转换
      - 新增 dto.BulkAssignResult 类型和对应的 mapper 函数
      739d0ee6
  17. 25 Dec, 2025 1 commit
  18. 24 Dec, 2025 1 commit
  19. 23 Dec, 2025 2 commits
    • dexcoder6's avatar
      feat: 添加用户余额充值/退款功能 (#17) · 50dba656
      dexcoder6 authored
      ## 功能特性
      
      ### 前端
      - 在用户列表操作列添加充值和退款按钮
      - 实现充值/退款对话框,支持输入金额和备注
      - 从编辑用户表单中移除余额字段,防止直接修改
      - 添加余额不足验证,实时显示操作后余额
      - 优化备注提示词,提供多种场景示例
      
      ### 后端
      - 为 redeem_codes 表添加 notes 字段(迁移文件)
      - 在 UpdateUserBalance 接口添加 notes 参数支持
      - 添加余额验证:金额必须大于0,操作后余额不能为负
      - UpdateUser 接口移除 balance 字段处理,防止误操作
      - 完整的审计日志和缓存管理
      
      ## 安全保护
      
      - 前端:余额不足时禁用提交按钮,实时提示
      - 后端:双重验证(输入金额 > 0 + 结果余额 >= 0)
      - 权限:仅管理员可访问(AdminAuth 中间件)
      - 审计:所有操作记录到 redeem_codes 表
      
      ## 修改文件
      
      后端:
      - backend/migrations/004_add_redeem_code_notes.sql
      - backend/internal/model/redeem_code.go
      - backend/internal/service/admin_service.go
      - backend/internal/handler/admin/user_handler.go
      
      前端:
      - frontend/src/views/admin/UsersView.vue
      - frontend/src/api/admin/users.ts
      - frontend/src/i18n/locales/zh.ts
      - frontend/src/i18n/locales/en.ts
      
      🤖 Generated with [Claude Code](https://claude.com/claude-code
      
      )
      Co-authored-by: default avatarClaude Sonnet 4.5 <noreply@anthropic.com>
      50dba656
    • dexcoder6's avatar
      feat: 增强用户管理功能,添加用户名、微信号和备注字段 · 0b8e84f9
      dexcoder6 authored
      - 新增User模型字段:username(用户名)、wechat(微信号)、notes(备注)
      - 扩展用户搜索功能,支持通过用户名和微信号搜索
      - 添加用户个人资料更新功能,用户可自行编辑用户名和微信号
      - 管理员用户列表新增用户名、微信号、备注显示列
      - 备注字段仅对管理员可见,增强数据安全性
      - 完善中英文国际化翻译
      - 修复国际化文件中重复属性的TypeScript错误
      
      🤖 Generated with [Claude Code](https://claude.com/claude-code
      
      )
      Co-Authored-By: default avatarClaude Sonnet 4.5 <noreply@anthropic.com>
      0b8e84f9
  20. 18 Dec, 2025 1 commit