修复2个问题,在mac上测试通过 - #40
Conversation
Updated GeoIP database download URLs for improved accuracy.
- Fix UpdateTarget to use explicit Select() to force bool zero-value (false) updates Previously GORM's Updates() silently skipped 'enabled=false' since bool zero value was treated as no-change, causing disable operations to be ignored. - Fix dashboard history query returning empty results due to timezone mismatch Frontend sends UTC timestamps via toISOString() but glebarez/sqlite stores time in local timezone, causing BETWEEN comparisons to fail. Added parseTimeParam() that converts parsed timestamps to local timezone before querying the database.
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe PR adds shared parsing for RFC3339 timestamps, uses inclusive history bounds, preserves false-valued target fields during updates, and changes the GeoIP database download source. ChangesHistory time handling
Target update fields
Database download sources
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/api/server.go`:
- Around line 393-401: Update handleHistory’s startStr and endStr parsing to
handle parseTimeParam errors explicitly: when either supplied parameter is
invalid, return HTTP 400 immediately and do not call GetHistory; preserve the
existing parsed values and default bounds for valid or omitted parameters.
In `@internal/monitor/service.go`:
- Around line 622-624: 统一 ensureGeoIPDatabase 与受保护手动更新流程使用的 GeoIP 下载地址:将当前
release URL 提取为共享配置,并让 internal/api/server.go
中的下载逻辑复用该配置,避免两条路径来源不一致;增加集成测试,验证两条路径写入的 MMDB 文件格式兼容且可正常使用。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 27ae4c4c-bbc1-4727-a018-0553b747c7a6
📒 Files selected for processing (3)
internal/api/server.gointernal/monitor/service.gopkg/storage/repo.go
📜 Review details
🔇 Additional comments (4)
internal/monitor/service.go (1)
639-639: LGTM!internal/api/server.go (1)
413-426: LGTM!pkg/storage/repo.go (2)
20-21: LGTM!
65-73: LGTM!
| if parsed, err := parseTimeParam(startStr); err == nil { | ||
| start = parsed | ||
| } | ||
| } | ||
| if endStr != "" { | ||
| if parsed, err := time.Parse(time.RFC3339, endStr); err == nil { | ||
| if parsed, err := parseTimeParam(endStr); err == nil { | ||
| end = parsed | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Reject invalid time parameters instead of using default bounds.
parseTimeParam returns an error, but handleHistory discards it. An invalid start silently uses the default six-hour window. An invalid end silently uses time.Now(). Return HTTP 400 before calling GetHistory when either supplied parameter is invalid.
Proposed fix
if startStr != "" {
- if parsed, err := parseTimeParam(startStr); err == nil {
- start = parsed
+ parsed, err := parseTimeParam(startStr)
+ if err != nil {
+ c.JSON(http.StatusBadRequest, gin.H{"error": "invalid start time"})
+ return
}
+ start = parsed
}
if endStr != "" {
- if parsed, err := parseTimeParam(endStr); err == nil {
- end = parsed
+ parsed, err := parseTimeParam(endStr)
+ if err != nil {
+ c.JSON(http.StatusBadRequest, gin.H{"error": "invalid end time"})
+ return
}
+ end = parsed
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if parsed, err := parseTimeParam(startStr); err == nil { | |
| start = parsed | |
| } | |
| } | |
| if endStr != "" { | |
| if parsed, err := time.Parse(time.RFC3339, endStr); err == nil { | |
| if parsed, err := parseTimeParam(endStr); err == nil { | |
| end = parsed | |
| } | |
| } | |
| parsed, err := parseTimeParam(startStr) | |
| if err != nil { | |
| c.JSON(http.StatusBadRequest, gin.H{"error": "invalid start time"}) | |
| return | |
| } | |
| start = parsed | |
| } | |
| if endStr != "" { | |
| parsed, err := parseTimeParam(endStr) | |
| if err != nil { | |
| c.JSON(http.StatusBadRequest, gin.H{"error": "invalid end time"}) | |
| return | |
| } | |
| end = parsed | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/api/server.go` around lines 393 - 401, Update handleHistory’s
startStr and endStr parsing to handle parseTimeParam errors explicitly: when
either supplied parameter is invalid, return HTTP 400 immediately and do not
call GetHistory; preserve the existing parsed values and default bounds for
valid or omitted parameters.
| //return downloadGeoIP(path, "https://raw.githubusercontent.com/sapics/ip-location-db/main/dbip-city-mmdb/dbip-city-ipv4.mmdb") | ||
| //return downloadGeoIP(path, "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/Country.mmdb") | ||
| return downloadGeoIP(path, "https://github.com/sapics/ip-location-db/releases/download/latest/dbip-city-ipv4.mmdb") |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
统一 GeoIP 数据库的下载来源。
ensureGeoIPDatabase 现在使用 release 资产,但 internal/api/server.go Line 792 仍从 main 分支下载同一数据库。启动时自动更新和受保护的手动更新可能使用不同版本,或在来源可用性不一致时产生不同结果。
请将下载地址提取到共享配置,并让两条路径使用同一来源。增加集成测试,确认两条路径写入兼容的 MMDB 文件。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/monitor/service.go` around lines 622 - 624, 统一 ensureGeoIPDatabase
与受保护手动更新流程使用的 GeoIP 下载地址:将当前 release URL 提取为共享配置,并让 internal/api/server.go
中的下载逻辑复用该配置,避免两条路径来源不一致;增加集成测试,验证两条路径写入的 MMDB 文件格式兼容且可正常使用。
本次提交包含的修复:
本次修复均使用AI进行修复,本地功能验证通过,请检查代码后再合并