-
Notifications
You must be signed in to change notification settings - Fork 11.1k
添加邀请返利开关;为所有模型路由添加claude-前缀 #6408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6040bab
e05e406
082b2e0
4d9a8cb
e66c0e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package controller | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/QuantumNous/new-api/common" | ||
| "github.com/gin-gonic/gin" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGetStatusIncludesAffiliateRewardsEnabled(t *testing.T) { | ||
| originalEnabled := common.AffiliateRewardsEnabled | ||
| originalOptionMap := common.OptionMap | ||
| t.Cleanup(func() { | ||
| common.AffiliateRewardsEnabled = originalEnabled | ||
| common.OptionMap = originalOptionMap | ||
| }) | ||
|
|
||
| common.AffiliateRewardsEnabled = false | ||
| common.OptionMap = map[string]string{ | ||
| "HeaderNavModules": "[]", | ||
| "SidebarModulesAdmin": "[]", | ||
| } | ||
|
|
||
| gin.SetMode(gin.TestMode) | ||
| recorder := httptest.NewRecorder() | ||
| context, _ := gin.CreateTestContext(recorder) | ||
| context.Request = httptest.NewRequest(http.MethodGet, "/api/status", nil) | ||
|
|
||
| GetStatus(context) | ||
|
|
||
| require.Equal(t, http.StatusOK, recorder.Code) | ||
|
|
||
| var payload struct { | ||
| Success bool `json:"success"` | ||
| Data struct { | ||
| AffiliateRewardsEnabled bool `json:"affiliate_rewards_enabled"` | ||
| } `json:"data"` | ||
| } | ||
| require.NoError(t, common.Unmarshal(recorder.Body.Bytes(), &payload)) | ||
| require.True(t, payload.Success) | ||
| assert.False(t, payload.Data.AffiliateRewardsEnabled) | ||
| } | ||
|
|
||
| func TestGetTopUpInfoIncludesAffiliateRewardsEnabled(t *testing.T) { | ||
| originalEnabled := common.AffiliateRewardsEnabled | ||
| t.Cleanup(func() { | ||
| common.AffiliateRewardsEnabled = originalEnabled | ||
| }) | ||
|
|
||
| common.AffiliateRewardsEnabled = false | ||
|
|
||
| gin.SetMode(gin.TestMode) | ||
| recorder := httptest.NewRecorder() | ||
| context, _ := gin.CreateTestContext(recorder) | ||
| context.Request = httptest.NewRequest(http.MethodGet, "/api/user/topup/info", nil) | ||
|
|
||
| GetTopUpInfo(context) | ||
|
|
||
| require.Equal(t, http.StatusOK, recorder.Code) | ||
|
|
||
| var payload struct { | ||
| Success bool `json:"success"` | ||
| Data struct { | ||
| AffiliateRewardsEnabled bool `json:"affiliate_rewards_enabled"` | ||
| } `json:"data"` | ||
| } | ||
| require.NoError(t, common.Unmarshal(recorder.Body.Bytes(), &payload)) | ||
| require.True(t, payload.Success) | ||
| assert.False(t, payload.Data.AffiliateRewardsEnabled) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -102,6 +102,7 @@ func GetTopUpInfo(c *gin.Context) { | |||||||||||||||
| "enable_waffo_topup": enableWaffo, | ||||||||||||||||
| "enable_waffo_pancake_topup": enableWaffoPancake, | ||||||||||||||||
| "enable_redemption": complianceConfirmed, | ||||||||||||||||
| "affiliate_rewards_enabled": common.AffiliateRewardsEnabled, | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 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.
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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| "payment_compliance_confirmed": complianceConfirmed, | ||||||||||||||||
| "payment_compliance_terms_version": operation_setting.CurrentComplianceTermsVersion, | ||||||||||||||||
| "waffo_pay_methods": func() interface{} { | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package model | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/QuantumNous/new-api/common" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestUpdateOptionMapUpdatesAffiliateRewardsEnabled(t *testing.T) { | ||
| originalEnabled := common.AffiliateRewardsEnabled | ||
| originalOptionMap := common.OptionMap | ||
| t.Cleanup(func() { | ||
| common.AffiliateRewardsEnabled = originalEnabled | ||
| common.OptionMap = originalOptionMap | ||
| }) | ||
|
|
||
| common.OptionMap = map[string]string{} | ||
| common.AffiliateRewardsEnabled = true | ||
|
|
||
| require.NoError(t, updateOptionMap("AffiliateRewardsEnabled", "false")) | ||
|
|
||
| assert.False(t, common.AffiliateRewardsEnabled) | ||
| assert.Equal(t, "false", common.OptionMap["AffiliateRewardsEnabled"]) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Make Anthropic aliases reversible and requester-scoped.
fooand a literalclaude-fooboth serialize asclaude-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 originalfoounrouteable 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