fix: When retrieving the model list with multiple keys, select the first enabled one. - #2260
Conversation
WalkthroughRefactored channel key retrieval in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 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: 0
🧹 Nitpick comments (1)
controller/channel.go (1)
206-216: Multi-key selection viaGetNextEnabledKeylooks correct; consider a couple of hardening tweaksThe switch to
channel.GetNextEnabledKey()plus trimming the returned key achieves the PR goal: multi-key channels will use the first enabled key instead of blindly taking the first line, while single-key channels should behave as before. Error handling with a JSON{success:false, message: ...}response is consistent with nearby code paths.Two small, non-blocking suggestions:
- Guard against unexpected empty keys
IfGetNextEnabledKeycan ever return""with anilerror (e.g., future refactor), you’d end up sendingAuthorization: Bearerupstream. A cheap defensive check here avoids a confusing 401 from the provider:key = strings.TrimSpace(key)
- if key == "" {
c.JSON(http.StatusOK, gin.H{"success": false,"message": "获取渠道密钥失败: 没有可用的密钥",})return- }
- Ensure error messages don’t leak key material
Please double‑check thatapiErr.Error()fromGetNextEnabledKeynever embeds the raw key or a large prefix of it. If it might, consider wrapping it in a more generic message here instead of interpolating the full error text.These are polish items; the core behavior change looks good and aligns with the multi‑key design in the rest of this file.
…-models fix: When retrieving the model list with multiple keys, select the first enabled one.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.