feat: 实现自动日志清理功能的 API 接口#7
Conversation
- 新增 /api/admin/system-config 端点 (GET/POST) - 支持自动清理配置的读取和更新 - 扩展验证 Schema 支持日志清理参数 - 更新 Server Actions 支持完整配置 修复 #6 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Ding <ding113@users.noreply.github.com>
|
Claude finished @ding113's task —— View job 代码审查完成 ✅任务清单:
代码审查结果✅ 整体评价代码实现质量良好,成功补充了自动日志清理功能的 API 接口。实现符合项目架构规范,认证、验证、错误处理都比较完善。 📋 详细审查1. API 路由实现 ( ✅ 优点:
问题 1:Schema 重复定义 (第 51-59 行)
问题 2:不安全的类型断言 (第 67 行)
2. 验证 Schema ( ✅ 优点:
✅ 无问题 3. Server Actions ( ✅ 优点:
✅ 无问题 🔍 其他观察架构一致性:
类型安全:
📝 修改建议高优先级:
低优先级:
✅ 测试建议PR 描述中的测试计划很完整,建议重点测试:
🏷️ 已添加标签
| View PR |
| const schema = z.object({ | ||
| siteTitle: z.string().min(1, "站点标题不能为空").max(128, "站点标题不能超过128个字符"), | ||
| allowGlobalUsageView: z.boolean(), | ||
| currencyDisplay: z.string().optional(), | ||
| enableAutoCleanup: z.boolean().optional(), | ||
| cleanupRetentionDays: z.number().int().min(1).max(365).optional(), | ||
| cleanupSchedule: z.string().min(1).optional(), | ||
| cleanupBatchSize: z.number().int().min(1000).max(100000).optional(), | ||
| }); |
There was a problem hiding this comment.
问题:Schema 重复定义
这里重新定义了验证 Schema,但 src/lib/validation/schemas.ts 中已经有 UpdateSystemSettingsSchema。
存在的差异:
- 这里:
currencyDisplay: z.string().optional() - schemas.ts:使用
z.enum()验证CURRENCY_CONFIG的键
影响: 绕过了货币类型的枚举验证,可能接受无效的货币代码。
建议修改:
import { UpdateSystemSettingsSchema } from "@/lib/validation/schemas";
// 删除第 51-59 行的 schema 定义
// 直接使用:
const validated = UpdateSystemSettingsSchema.parse(body);| const updated = await updateSystemSettings({ | ||
| siteTitle: validated.siteTitle.trim(), | ||
| allowGlobalUsageView: validated.allowGlobalUsageView, | ||
| currencyDisplay: validated.currencyDisplay as any, |
There was a problem hiding this comment.
问题:不安全的类型断言
使用 as any 绕过了 TypeScript 类型检查。
如果使用 UpdateSystemSettingsSchema(已在 schemas.ts 中定义),这个类型断言就不需要了,因为验证后的类型会自动匹配 UpdateSystemSettingsInput。
✅ 移除 API 路由中的重复 Schema 定义 ✅ 导入并使用 UpdateSystemSettingsSchema ✅ 移除不安全的 as any 类型断言 ✅ 修复 ZodError.errors → ZodError.issues ✅ 确保货币类型枚举验证正确执行 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude finished @ding113's task —— View job 代码审查完成 ✅任务清单:
审查结果✅ 之前的问题已全部解决问题 1:Schema 重复定义 ✅ 已修复
问题 2:不安全的类型断言 ✅ 已修复
📋 代码质量评估1. API 路由实现 (
|
- Extract QUERY_CLIENT_DEFAULTS from AppProviders so test imports the actual config instead of duplicating it (bugbot #5) - Store shared-timer state on globalThis for HMR safety, matching the pattern already used in session-cache (bugbot #6) - Rename clearAllSessionsCache -> clearAllSessionsQueryCache and clearAllSessionCache -> clearAllCaches to eliminate single-char naming confusion (bugbot #7)
…and timers (#815) * fix(dashboard): prevent memory leaks from unbounded polling, caches, and timers - Configure QueryClient with gcTime=2min, staleTime=30s, and refetchIntervalInBackground=false to stop all 11 polling queries from firing in hidden browser tabs - Cap useInfiniteQuery to maxPages=5 (250 entries) to prevent unbounded page accumulation in the logs table - Replace per-instance setInterval in RelativeTime with a shared 10s tick emitter (O(1) timers instead of O(n)) - Migrate SessionCache from unbounded Map to TTLMap with LRU eviction (activeSessionsCache maxSize=100, sessionDetailsCache maxSize=10000) - Hoist formatResponseTime to module scope to avoid per-render closure allocation - Add refreshWhenHidden=false to big-screen SWR configs * fix: address PR #815 review comments - Move misplaced JSDoc from formatResponseTime to calcPercentageChange - Log errors in shared-timer catch block instead of silently swallowing - Use @/ path alias for ttl-map import in session-cache * fix: address remaining PR #815 review comments - Extract QUERY_CLIENT_DEFAULTS from AppProviders so test imports the actual config instead of duplicating it (bugbot #5) - Store shared-timer state on globalThis for HMR safety, matching the pattern already used in session-cache (bugbot #6) - Rename clearAllSessionsCache -> clearAllSessionsQueryCache and clearAllSessionCache -> clearAllCaches to eliminate single-char naming confusion (bugbot #7)
摘要
修复 ##6 - 实现自动日志清理功能的缺失 API 接口。
修改内容
/api/admin/system-config端点 (GET/POST)测试计划
🤖 Generated with Claude Code