添加邀请返利开关;为所有模型路由添加claude-前缀 - #6408
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (15)
🚧 Files skipped from review as they are similar to previous changes (15)
WalkthroughThe PR adds an ChangesAffiliate rewards and Anthropic model handling
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Wallet
participant TopupAPI
participant useAffiliate
participant AffiliateRewardsCard
Wallet->>TopupAPI: request top-up information
TopupAPI-->>Wallet: affiliate_rewards_enabled
Wallet->>useAffiliate: pass enabled flag
useAffiliate-->>Wallet: affiliate data or cleared state
Wallet->>AffiliateRewardsCard: render when enabled
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
web/src/features/wallet/hooks/use-affiliate.ts (1)
46-69: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winInvalidate in-flight requests when the feature is disabled.
A request started with
enabled === truecan resolve after Lines 99-107 clear the state; the old closure still writesaffiliateCodeandaffiliateLink. A rapid disable/re-enable can therefore display stale data before the fresh request completes. Use request-generation checks or cancellation, and invalidate the previous request on disable.Also applies to: 99-107
🤖 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 `@web/src/features/wallet/hooks/use-affiliate.ts` around lines 46 - 69, Update fetchAffiliateCode and the enabled-disabled cleanup path to invalidate any in-flight affiliate-code request when the feature is disabled. Use a request-generation check or cancellation mechanism so responses from earlier requests cannot update affiliateCode or affiliateLink after disable or rapid re-enable; only the current request may commit state.
🧹 Nitpick comments (2)
web/src/features/wallet/hooks/use-affiliate.ts (1)
33-41: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd an explicit return type to the public hook.
useAffiliateis exported but its return contract is inferred. Define a result type and annotateuseAffiliate(...): UseAffiliateResult.As per coding guidelines, web TypeScript functions should have explicit parameter and return types.
🤖 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 `@web/src/features/wallet/hooks/use-affiliate.ts` around lines 33 - 41, Define a public UseAffiliateResult type describing the hook’s returned values, then annotate the exported useAffiliate function with UseAffiliateResult while retaining its existing UseAffiliateOptions parameter type and behavior.Source: Coding guidelines
web/src/features/system-settings/billing/section-registry.tsx (1)
58-66: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winConsider a fallback for
AffiliateRewardsEnabledlike other optional flags in this file.Other settings here (
WaffoEnabled ?? false,compliance_confirmed ?? false) defensively fall back when the backend value may be absent.AffiliateRewardsEnabledhas no fallback, so if the fetched settings payload ever omits this new field (e.g., a stale cache before backend rollout), it will passundefinedthrough to theSwitch'scheckedprop, risking a React controlled/uncontrolled warning.🛡️ Proposed fix
- AffiliateRewardsEnabled: settings.AffiliateRewardsEnabled, + AffiliateRewardsEnabled: settings.AffiliateRewardsEnabled ?? true,🤖 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 `@web/src/features/system-settings/billing/section-registry.tsx` around lines 58 - 66, Update the AffiliateRewardsEnabled mapping in the build function to default missing backend values to false, matching the existing optional-flag handling such as WaffoEnabled and compliance_confirmed. Preserve the provided boolean when present so QuotaSettingsSection always receives a defined checked value.
🤖 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 `@controller/model.go`:
- Around line 271-281: Make Anthropic model aliases reversible and scoped to the
requesting user/group: in controller/model.go:271-281, prevent collisions
between foo and literal claude-foo by enforcing a reserved-prefix invariant or
maintaining a per-user alias map; in controller/model.go:339-351, resolve IDs
only through the caller-visible mapping; in model/ability.go:57-70, provide
group/requester-scoped lookup where existence checks remain; in
middleware/distributor.go:41-43, pass the effective user/group context; and in
middleware/distributor.go:179-190, remove global ability-based alias
disambiguation so inaccessible abilities cannot affect routing.
In `@controller/topup.go`:
- Line 105: Update GetTopUpInfo’s read of common.AffiliateRewardsEnabled to use
common.OptionMapRWMutex for synchronization, acquiring the appropriate read lock
before accessing the feature flag and releasing it afterward; preserve the
existing affiliate_rewards_enabled response value.
---
Outside diff comments:
In `@web/src/features/wallet/hooks/use-affiliate.ts`:
- Around line 46-69: Update fetchAffiliateCode and the enabled-disabled cleanup
path to invalidate any in-flight affiliate-code request when the feature is
disabled. Use a request-generation check or cancellation mechanism so responses
from earlier requests cannot update affiliateCode or affiliateLink after disable
or rapid re-enable; only the current request may commit state.
---
Nitpick comments:
In `@web/src/features/system-settings/billing/section-registry.tsx`:
- Around line 58-66: Update the AffiliateRewardsEnabled mapping in the build
function to default missing backend values to false, matching the existing
optional-flag handling such as WaffoEnabled and compliance_confirmed. Preserve
the provided boolean when present so QuotaSettingsSection always receives a
defined checked value.
In `@web/src/features/wallet/hooks/use-affiliate.ts`:
- Around line 33-41: Define a public UseAffiliateResult type describing the
hook’s returned values, then annotate the exported useAffiliate function with
UseAffiliateResult while retaining its existing UseAffiliateOptions parameter
type and behavior.
🪄 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: CHILL
Plan: Pro Plus
Run ID: 4497fe41-54d9-4e6c-93fd-387156ba1ded
📒 Files selected for processing (28)
common/constants.gocontroller/misc.gocontroller/model.gocontroller/status_affiliate_rewards_test.gocontroller/topup.gomiddleware/distributor.gomodel/ability.gomodel/option.gomodel/option_affiliate_rewards_test.goweb/src/features/auth/types.tsweb/src/features/system-settings/billing/index.tsxweb/src/features/system-settings/billing/section-registry.tsxweb/src/features/system-settings/general/quota-settings-section.tsxweb/src/features/system-settings/types.tsweb/src/features/wallet/hooks/use-affiliate.tsweb/src/features/wallet/index.tsxweb/src/features/wallet/lib/affiliate.test.tsweb/src/features/wallet/lib/affiliate.tsweb/src/features/wallet/types.tsweb/src/hooks/use-system-config.tsweb/src/i18n/locales/en.jsonweb/src/i18n/locales/fr.jsonweb/src/i18n/locales/ja.jsonweb/src/i18n/locales/ru.jsonweb/src/i18n/locales/vi.jsonweb/src/i18n/locales/zh-TW.jsonweb/src/i18n/locales/zh.jsonweb/src/stores/system-config-store.ts
| for i, m := range userOpenAiModels { | ||
| id := m.Id | ||
| if !strings.HasPrefix(id, "claude-") { | ||
| id = "claude-" + id | ||
| } | ||
| useranthropicModels[i] = dto.AnthropicModel{ | ||
| ID: model.Id, | ||
| CreatedAt: time.Unix(int64(model.Created), 0).UTC().Format(time.RFC3339), | ||
| DisplayName: model.Id, | ||
| ID: id, | ||
| CreatedAt: time.Unix(int64(m.Created), 0).UTC().Format(time.RFC3339), | ||
| DisplayName: m.Id, | ||
| Type: "model", | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Make Anthropic aliases reversible and requester-scoped.
foo and a literal claude-foo both serialize as claude-foo. Retrieval and routing then prefer the literal model; moreover, an ability in another group can make routing preserve an ID the current user cannot access. This yields duplicate listings and makes the original foo unrouteable through /v1/messages.
controller/model.go#L271-L281: prevent emitting colliding IDs; enforce a reserved-prefix invariant or expose a per-user reversible alias map.controller/model.go#L339-L351: resolve against that caller-visible mapping rather than global exact-key precedence.model/ability.go#L57-L70: provide a group/requester-scoped lookup if existence checks remain part of resolution.middleware/distributor.go#L41-L43: perform resolution with the effective user/group context.middleware/distributor.go#L179-L190: do not use global ability existence to disambiguate aliases.
📍 Affects 3 files
controller/model.go#L271-L281(this comment)controller/model.go#L339-L351model/ability.go#L57-L70middleware/distributor.go#L41-L43middleware/distributor.go#L179-L190
🤖 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 `@controller/model.go` around lines 271 - 281, Make Anthropic model aliases
reversible and scoped to the requesting user/group: in
controller/model.go:271-281, prevent collisions between foo and literal
claude-foo by enforcing a reserved-prefix invariant or maintaining a per-user
alias map; in controller/model.go:339-351, resolve IDs only through the
caller-visible mapping; in model/ability.go:57-70, provide
group/requester-scoped lookup where existence checks remain; in
middleware/distributor.go:41-43, pass the effective user/group context; and in
middleware/distributor.go:179-190, remove global ability-based alias
disambiguation so inaccessible abilities cannot affect routing.
| "enable_waffo_topup": enableWaffo, | ||
| "enable_waffo_pancake_topup": enableWaffoPancake, | ||
| "enable_redemption": complianceConfirmed, | ||
| "affiliate_rewards_enabled": common.AffiliateRewardsEnabled, |
There was a problem hiding this comment.
🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -n -C3 'AffiliateRewardsEnabled|OptionMapRWMutex' controller/topup.go model/option.go controller/misc.goRepository: QuantumNous/new-api
Length of output: 5469
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== common files with AffiliateRewardsEnabled/OptionMapRWMutex declarations =="
rg -n -C2 'var OptionMapRWMutex|type OptionMapRWMutex|AffiliateRewardsEnabled' -S --glob '*.go' .
echo
echo "== controller/topup.go relevant sections =="
fd -a 'topup\.go$' . | sed 's#^\./##' | while read -r f; do
echo "--- $f ($(wc -l < "$f") lines) ---"
rg -n -C8 'GetTopUpInfo|affiliate_rewards_enabled|OptionMapRWMutex' "$f" || true
done
echo
echo "== direct reads/writes of AffiliateRewardsEnabled in Go sources =="
python3 - <<'PY'
import re, pathlib
for p in pathlib.Path('.').rglob('*.go'):
s=p.read_text(errors='ignore').splitlines()
for i,line in enumerate(s,1):
if 'common.AffiliateRewardsEnabled' in line or 'AffiliateRewardsEnabled = ' in line:
print(f"{p}:{i}: {line.strip()}")
PYRepository: QuantumNous/new-api
Length of output: 9925
Protect the feature-flag read with the configuration lock.
model/option.go writes common.AffiliateRewardsEnabled while holding common.OptionMapRWMutex, but controller/topup.go reads it directly. This unprotected read from GetTopUpInfo can race with an option update and expose undefined or stale top-up visibility.
Proposed fix
+ common.OptionMapRWMutex.RLock()
+ affiliateRewardsEnabled := common.AffiliateRewardsEnabled
+ common.OptionMapRWMutex.RUnlock()
+
data := gin.H{
- "affiliate_rewards_enabled": common.AffiliateRewardsEnabled,
+ "affiliate_rewards_enabled": affiliateRewardsEnabled,📝 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.
| "affiliate_rewards_enabled": common.AffiliateRewardsEnabled, | |
| common.OptionMapRWMutex.RLock() | |
| affiliateRewardsEnabled := common.AffiliateRewardsEnabled | |
| common.OptionMapRWMutex.RUnlock() | |
| data := gin.H{ | |
| "affiliate_rewards_enabled": affiliateRewardsEnabled, |
🤖 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 `@controller/topup.go` at line 105, Update GetTopUpInfo’s read of
common.AffiliateRewardsEnabled to use common.OptionMapRWMutex for
synchronization, acquiring the appropriate read lock before accessing the
feature flag and releasing it afterward; preserve the existing
affiliate_rewards_enabled response value.
|
That doesn't seem quite right. The display name is specific to Anthropic, while other agent clients only read the model ID. |
You're right. I only considered the Claude Code Desktop. |
Important
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
1.不开放邀请的时候,用户登录不会显示邀请返利链接板块;
2.添加claude-前缀可以让claude code desktop客户端识别到密钥可访问的所有模型
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit