程序猿MT
fd8473f267
Merge branch 'Wei-Shaw:main' into main
2026-01-12 10:28:22 +08:00
IanShaw027
ce3336e3f4
fix(lint): 修复代码格式和未使用变量问题
...
- 修复 ops_ws_handler.go 中的代码格式和返回值
- 移除 ops_repo_latency_histogram_buckets.go 中不必要的错误检查
- 修复 api_contract_test.go 缩进并添加运维监控配置项测试
- 移除 ops_cleanup_service.go 中未使用的变量
- 添加 ops_retry.go 中缺失的 status 字段
2026-01-11 23:40:09 +08:00
IanShaw027
54c5788b86
fix(lint): 修复所有golangci-lint错误
...
- 修复depguard错误:为ops service文件添加redis导入例外
- 修复errcheck错误:添加错误检查和类型断言检查
- 修复gofmt错误:格式化代码
- 修复ineffassign错误:移除无效的idx++赋值
- 修复staticcheck错误:合并条件赋值
- 修复unused错误:移除未使用的字段和函数
- ops_cleanup_service.go: entryID字段
- ops_retry.go: status字段
- ops_upstream_context.go: getOpsUpstreamErrors函数
2026-01-11 23:26:29 +08:00
IanShaw027
3dfb62e996
merge: 合并main分支最新改动
...
解决冲突:
- backend/internal/config/config.go: 合并Ops和Dashboard配置
- backend/internal/server/api_contract_test.go: 合并handler初始化
- backend/internal/service/openai_gateway_service.go: 保留Ops错误追踪逻辑
- backend/internal/service/wire.go: 合并Ops和APIKeyAuth provider
主要合并内容:
- Dashboard缓存和预聚合功能
- API Key认证缓存优化
- Codex转换支持
- 使用日志分区表
2026-01-11 23:15:01 +08:00
yangjianbo
18b8bd43ad
fix(限流): 原子化 Redis 限流并支持故障策略
...
使用 Lua 脚本原子设置计数与过期,修复 TTL 缺失\n支持 fail-open/fail-close 并对优惠码验证启用 fail-close\n新增单元与集成测试覆盖关键分支\n\n测试:go test ./...
2026-01-11 22:21:05 +08:00
yangjianbo
32953405b1
fix(账号管理): 调度批量结果明细与刷新优化
...
补充批量调度返回 success_ids/failed_ids 并增加合约/单测
前端加入降级处理与部分失败提示,表格行使用稳定 key
测试: make test-frontend
测试: go test ./internal/service -run BulkUpdateAccounts -tags=unit
测试: go test ./internal/server -run APIContracts -tags=unit
2026-01-11 20:22:17 +08:00
IanShaw027
c1a3dd41dd
feat(ops): 添加运维监控配置开关
...
- 在 .env.example 和 config.example.yaml 中添加 ops.enabled 配置项
- 默认值为 true,保持现有行为
- 当设置为 false 时,左侧栏隐藏运维监控菜单并禁用所有运维监控功能
- 修改后端 GetSettings API,让 ops_monitoring_enabled 受 config.ops.enabled 控制
- 数据清理和预聚合任务默认保持开启状态(通过运维监控设置对话框配置)
2026-01-11 20:10:08 +08:00
IanShaw027
988b4d0254
feat(ops): 添加高级设置API支持
...
- 新增OpsAdvancedSettings数据模型
- 支持数据保留策略配置(错误日志、分钟级指标、小时级指标)
- 支持数据聚合开关配置
- 添加GET/PUT /admin/ops/advanced-settings接口
- 添加配置校验和默认值处理
相关文件:
- backend/internal/service/ops_settings_models.go
- backend/internal/service/ops_settings.go
- backend/internal/handler/admin/ops_settings_handler.go
- backend/internal/server/routes/admin.go
- backend/internal/service/domain_constants.go
2026-01-11 19:51:18 +08:00
yangjianbo
1240c78ef6
Merge branch 'test' into dev
2026-01-11 18:22:07 +08:00
yangjianbo
1a869547d7
feat(仪表盘): 引入预聚合统计与聚合作业
2026-01-11 16:01:35 +08:00
IanShaw027
645609d441
merge: 正确合并 main 分支改动
...
合并 origin/main 最新改动,正确保留所有配置:
- Ops 运维监控配置和功能
- LinuxDo Connect OAuth 配置
- Update 在线更新配置
- 优惠码功能
- 其他 main 分支新功能
修复之前合并时错误删除 LinuxDo 和 Update 配置的问题。
2026-01-11 11:41:10 +08:00
yangjianbo
cb3e08dda4
fix(认证): 补齐余额与删除场景缓存失效
...
为 Usage/Promo/Redeem 注入认证缓存失效逻辑
删除用户与分组前先失效认证缓存降低窗口
补充回归测试验证失效调用
测试: make test
2026-01-11 10:55:25 +08:00
yangjianbo
44a93c1922
perf(认证): 引入 API Key 认证缓存与轻量删除查询
...
增加 L1/L2 缓存、负缓存与单飞回源
使用 key+owner 轻量查询替代全量加载并清理旧接口
补充缓存失效与余额更新测试,修复随机抖动 lint
测试: make test
2026-01-11 10:55:25 +08:00
yangjianbo
99e2391b2a
fix(认证): 补齐余额与删除场景缓存失效
...
为 Usage/Promo/Redeem 注入认证缓存失效逻辑
删除用户与分组前先失效认证缓存降低窗口
补充回归测试验证失效调用
测试: make test
2026-01-10 22:52:13 +08:00
yangjianbo
9d0a4f3d68
perf(认证): 引入 API Key 认证缓存与轻量删除查询
...
增加 L1/L2 缓存、负缓存与单飞回源
使用 key+owner 轻量查询替代全量加载并清理旧接口
补充缓存失效与余额更新测试,修复随机抖动 lint
测试: make test
2026-01-10 22:23:51 +08:00
Edric Li
0772cdda0f
fix: update API contract test for home_content field and fix gofmt
2026-01-10 19:01:00 +08:00
Edric Li
f6f072cb9a
Merge branch 'main' into feat/api-key-ip-restriction
2026-01-10 18:49:50 +08:00
Edric Li
5265b12cc7
feat(settings): add home content customization and config injection
...
- Add home_content setting for custom homepage (HTML or iframe URL)
- Inject public settings into index.html to eliminate page flash
- Support ETag caching with automatic invalidation on settings update
- Add Vite plugin for dev mode settings injection
- Refactor HomeView to use appStore instead of local API calls
2026-01-10 18:37:44 +08:00
shaw
d1a6d6b1cf
Merge branch 'mt21625457/main'
2026-01-10 14:44:58 +08:00
IanShaw027
3a67002cfe
merge: 合并主分支改动并保留 ops 监控实现
...
合并 main 分支的最新改动到 ops 监控分支。
冲突解决策略:保留当前分支的 ops 相关改动,接受主分支的其他改动。
保留的 ops 改动:
- 运维监控配置和依赖注入
- 运维监控 API 处理器和中间件
- 运维监控服务层和数据访问层
- 运维监控前端界面和状态管理
接受的主分支改动:
- Linux DO OAuth 集成
- 账号过期功能
- IP 地址限制功能
- 用量统计优化
- 其他 bug 修复和功能改进
2026-01-10 13:24:40 +08:00
long
9f4d4e5adf
feat: 实现注册优惠码功能
...
- 支持创建/编辑/删除优惠码,设置赠送金额和使用限制
- 注册页面实时验证优惠码并显示赠送金额
- 支持 URL 参数自动填充 (?promo=CODE)
- 添加优惠码验证接口速率限制
- 使用数据库行锁防止并发超限
- 新增后台优惠码管理页面,支持复制注册链接
2026-01-10 13:23:03 +08:00
long
d2fc14fb97
feat: 实现注册优惠码功能
...
- 支持创建/编辑/删除优惠码,设置赠送金额和使用限制
- 注册页面实时验证优惠码并显示赠送金额
- 支持 URL 参数自动填充 (?promo=CODE)
- 添加优惠码验证接口速率限制
- 使用数据库行锁防止并发超限
- 新增后台优惠码管理页面,支持复制注册链接
2026-01-10 13:14:35 +08:00
yangjianbo
297f08c683
Merge branch 'test' into dev
2026-01-10 09:39:02 +08:00
yangjianbo
435f693892
test(分组): 增加无效上下文覆盖回归测试
...
补充 GatewayService 与 APIKey 中间件对无效 ctxkey.Group 的覆盖行为测试
测试: make test-backend
2026-01-10 09:27:47 +08:00
yangjianbo
72f78f8a56
fix(分组): 强化上下文分组可信校验
...
- 引入 Hydrated 标记限制复用来源
- 无效上下文分组允许被新值覆盖自愈
- 更新相关单测覆盖
2026-01-10 08:40:27 +08:00
yangjianbo
2597fe78ba
fix(分组): 防止降级环并校验上下文分组
...
- 增加降级链路环检测并拦截配置
- 仅复用合法分组上下文并必要时回退查询
- 标注 GetByIDLite 轻量语义并补充测试
2026-01-10 07:56:50 +08:00
IanShaw027
585257d340
feat(运维监控): 增强监控功能和健康评分系统
...
后端改进:
- 新增健康评分计算服务(ops_health_score.go)
- 添加分布式锁支持(ops_advisory_lock.go)
- 优化指标采集和聚合逻辑
- 新增运维指标采集间隔配置(60-3600秒)
- 移除未使用的WebSocket查询token认证中间件
- 改进清理服务和告警评估逻辑
前端改进:
- 简化OpsDashboard组件结构
- 完善国际化文本(中英文)
- 新增运维监控相关API类型定义
- 添加运维指标采集间隔设置界面
- 优化错误详情模态框
测试:
- 添加健康评分单元测试
- 更新API契约测试
2026-01-10 01:38:47 +08:00
yangjianbo
675543240e
perf(网关): 复用分组上下文减少热路径查询
...
新增 GetByIDLite 并在网关与 Gemini 选择流程复用上下文 group,避免 COUNT 触发
更新 API key 中间件注入 group 上下文,减少重复查库
补充 gateway/gemini 中间件与仓库层回归测试
测试: make test
2026-01-09 23:01:42 +08:00
Edric.Li
0a4641c24e
feat(api-key): 添加 IP 白名单/黑名单限制功能 ( #221 )
...
* feat(api-key): add IP whitelist/blacklist restriction and usage log IP tracking
- Add IP restriction feature for API keys (whitelist/blacklist with CIDR support)
- Add IP address logging to usage logs (admin-only visibility)
- Remove billing_type column from usage logs UI (redundant)
- Use generic "Access denied" error message for security
Backend:
- New ip package with IP/CIDR validation and matching utilities
- Database migrations for ip_whitelist, ip_blacklist (api_keys) and ip_address (usage_logs)
- Middleware IP restriction check after API key validation
- Input validation for IP/CIDR patterns on create/update
Frontend:
- API key form with enable toggle for IP restriction
- Shield icon indicator in table for keys with IP restriction
- Removed billing_type filter and column from usage views
* fix: update API contract tests for ip_whitelist/ip_blacklist fields
Add ip_whitelist and ip_blacklist fields to expected JSON responses
in API contract tests to match the new API key schema.
2026-01-09 21:59:32 +08:00
Edric Li
e83f644c3f
fix: update API contract tests for ip_whitelist/ip_blacklist fields
...
Add ip_whitelist and ip_blacklist fields to expected JSON responses
in API contract tests to match the new API key schema.
2026-01-09 21:37:07 +08:00
Edric Li
6b97a8be28
Merge branch 'main' into feat/api-key-ip-restriction
2026-01-09 21:34:28 +08:00
Edric Li
90798f14b5
feat(api-key): add IP whitelist/blacklist restriction and usage log IP tracking
...
- Add IP restriction feature for API keys (whitelist/blacklist with CIDR support)
- Add IP address logging to usage logs (admin-only visibility)
- Remove billing_type column from usage logs UI (redundant)
- Use generic "Access denied" error message for security
Backend:
- New ip package with IP/CIDR validation and matching utilities
- Database migrations for ip_whitelist, ip_blacklist (api_keys) and ip_address (usage_logs)
- Middleware IP restriction check after API key validation
- Input validation for IP/CIDR patterns on create/update
Frontend:
- API key form with enable toggle for IP restriction
- Shield icon indicator in table for keys with IP restriction
- Removed billing_type filter and column from usage views
2026-01-09 21:24:59 +08:00
IanShaw027
e846458009
test(后端): 更新 API 契约测试支持 ops 监控端点
...
- 更新 api_contract_test.go 包含 ops 相关端点测试
2026-01-09 20:58:01 +08:00
IanShaw027
e0d12b46d8
feat(路由): 集成运维监控路由到服务器
...
- 更新路由器注册 ops 监控路由
- 添加 ops 管理路由(dashboard, alerts, realtime, settings, ws)
- 更新 gateway 路由支持请求追踪
- 集成 ops 服务到 HTTP 服务器
2026-01-09 20:55:12 +08:00
IanShaw027
f3ed95d4de
feat(handler): 实现运维监控 API 处理器和中间件
...
- 新增 ops 错误日志记录器(ops_error_logger.go)
- 新增 ops 主处理器(ops_handler.go)
- 新增告警管理处理器(ops_alerts_handler.go)
- 新增仪表板处理器(ops_dashboard_handler.go)
- 新增实时监控处理器(ops_realtime_handler.go)
- 新增配置管理处理器(ops_settings_handler.go)
- 新增 WebSocket 处理器(ops_ws_handler.go)
- 扩展设置 DTO 支持 ops 配置
- 新增客户端请求 ID 中间件(client_request_id.go)
- 新增 WebSocket 查询令牌认证中间件(ws_query_token_auth.go)
- 更新管理员认证中间件支持 ops 路由
- 注册 handler 依赖注入
2026-01-09 20:54:26 +08:00
shaw
62dc0b953b
Merge branch 'fix/table-pagination-and-features'
2026-01-09 20:42:05 +08:00
IanShaw027
7c3d5cadd5
fix(admin): 代码审查修复 - 输入验证和测试完善
...
根据 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 阻塞问题)
- 提升测试覆盖率
2026-01-09 19:43:19 +08:00
admin
d1c2a61d19
refactor(auth): 将 Linux DO OAuth 配置迁移到系统设置
...
- 将 LinuxDo Connect 配置从环境变量迁移到数据库持久化
- 在管理后台系统设置中添加 LinuxDo OAuth 配置项
- 简化部署流程,无需修改 docker-compose.override.yml
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-09 18:26:32 +08:00
admin
152d0cdec6
feat(auth): 添加 Linux DO Connect OAuth 登录支持
...
- 新增 Linux DO OAuth 配置项和环境变量支持
- 实现 OAuth 授权流程和回调处理
- 前端添加 Linux DO 登录按钮和回调页面
- 支持通过 Linux DO 账号注册/登录
- 添加相关国际化文本
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-09 18:26:32 +08:00
Edric Li
958ffe7a8a
test: fix unit tests for user_agent and proxy repo interface
...
- Add user_agent field to API contract test expectation
- Add ListWithFiltersAndAccountCount stub to proxyRepoStub
2026-01-08 21:44:18 +08:00
shaw
a3b81ef7bc
fix(test): 补充 stubUsageLogRepo 缺失的 GetStatsWithFilters 方法
2026-01-06 22:35:22 +08:00
song
195e227c04
merge: 合并 upstream/main 并保留本地图片计费功能
2026-01-06 10:49:26 +08:00
song
0400fcdca4
fix: 更新 API 合同测试,添加 image_count 和 image_size 字段
2026-01-05 17:31:23 +08:00
IanShaw027
06216aad53
fix(backend): 修复 CI 失败问题
...
修复内容:
1. 修复 6 个 golangci-lint 错误
- 3 个 errcheck 错误:在 gateway_request_test.go 中添加类型断言检查
- 3 个 gofmt 格式化问题:修复代码格式
2. 修复 API 契约测试失败
- 在测试中添加缺失的字段:enable_identity_patch 和 identity_patch_prompt
所有测试和 linter 检查现已通过。
2026-01-05 00:56:48 +08:00
yangjianbo
5dd8b8802b
fix(后端): 修复 lint 失败并清理无用代码
...
修正测试中的 APIKey 名称引用
移除不可达返回与未使用函数
统一 gofmt 格式并处理 Close 错误
2026-01-04 22:10:32 +08:00
yangjianbo
7dddd06583
Merge branch 'main' of https://github.com/mt21625457/aicodex2api
2026-01-04 21:06:12 +08:00
IanShaw027
a4953785d9
fix(lint): 修复所有 Go 命名规范问题
...
- 全局替换 ApiKey → APIKey(类型、字段、方法、变量)
- 修复所有 initialism 命名(API, SMTP, HTML, URL 等)
- 添加所有缺失的包注释
- 修复导出符号的注释格式
主要修改:
- ApiKey → APIKey(所有出现的地方)
- ApiKeyID → APIKeyID
- ApiKeyIDs → APIKeyIDs
- TestSmtpConnection → TestSMTPConnection
- HtmlURL → HTMLURL
- 添加 20+ 个包注释
- 修复 10+ 个导出符号注释格式
验证结果:
- ✓ golangci-lint: 0 issues
- ✓ 单元测试: 通过
- ✓ 集成测试: 通过
2026-01-04 19:28:20 +08:00
IanShaw027
603b361fb9
fix(test): 修复 api_contract_test 的接口签名和参数问题
2026-01-04 17:21:13 +08:00
ianshaw
71bf5b9e77
fix(usage): 使用日志事务和幂等性修复
...
- UsageLogRepository.Create 返回 inserted 标志
- UsageService 使用事务保证原子性
- 避免重复扣费(幂等重试场景)
- 更新依赖注入和测试
2026-01-03 17:10:32 -08:00
ianshaw
75e7c3dd06
fix(test): 修复测试文件与函数签名不匹配问题
2026-01-03 06:52:50 -08:00