Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/src/pages/Accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function Accounts() {
const [page, setPage] = useState(1)
const [statusFilter, setStatusFilter] = useState<'all' | 'normal' | 'rate_limited' | 'banned' | 'locked'>('all')
const [searchQuery, setSearchQuery] = useState('')
const [planFilter, setPlanFilter] = useState<'all' | 'pro' | 'team' | 'free'>('all')
const [planFilter, setPlanFilter] = useState<'all' | 'pro' | 'plus' | 'team' | 'free'>('all')
const [sortKey, setSortKey] = useState<'requests' | 'usage' | 'importTime' | null>(null)
const [sortDir, setSortDir] = useState<'asc' | 'desc'>('desc')

Expand Down Expand Up @@ -916,7 +916,7 @@ export default function Accounts() {
/>
</div>
<div className="flex items-center gap-1 rounded-lg border border-border bg-muted/30 p-0.5">
{(['all', 'pro', 'team', 'free'] as const).map((key) => (
{(['all', 'pro', 'plus', 'team', 'free'] as const).map((key) => (
<button
key={key}
onClick={() => { setPlanFilter(key); setPage(1) }}
Expand Down
6 changes: 3 additions & 3 deletions proxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1268,8 +1268,8 @@ func (h *Handler) compute429Cooldown(account *auth.Account, body []byte, resp *h
// Free 只有 7d 窗口,429 = 额度耗尽,冷却 7 天
return 7 * 24 * time.Hour

case "team", "pro", "enterprise":
// Team/Pro 有 5h + 7d 双窗口,需要判断是哪个窗口触发了限制
case "team", "teamplus", "pro", "plus", "enterprise":
// Team/Pro/Plus 有 5h + 7d 双窗口,需要判断是哪个窗口触发了限制
return h.detectTeamCooldownWindow(resp)

default:
Expand All @@ -1278,7 +1278,7 @@ func (h *Handler) compute429Cooldown(account *auth.Account, body []byte, resp *h
}
}

// detectTeamCooldownWindow 通过响应头判断 Team/Pro 账号是哪个窗口触发的限制
// detectTeamCooldownWindow 通过响应头判断 Team/Pro/Plus 账号是哪个窗口触发的限制
func (h *Handler) detectTeamCooldownWindow(resp *http.Response) time.Duration {
if resp == nil {
return 5 * time.Hour // 保守默认
Expand Down
36 changes: 36 additions & 0 deletions proxy/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"net/http/httptest"
"path/filepath"
"testing"
"time"

"github.com/codex2api/auth"
"github.com/codex2api/database"
"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -136,6 +138,40 @@ func TestSendFinalUpstreamError_Non429StatusPassthrough(t *testing.T) {
}
}

func TestCompute429CooldownPlusUsesWindowHeaders(t *testing.T) {
handler := &Handler{}
account := &auth.Account{PlanType: "plus"}
resp := &http.Response{
Header: make(http.Header),
}
resp.Header.Set("x-codex-primary-used-percent", "100")
resp.Header.Set("x-codex-primary-window-minutes", "300")
resp.Header.Set("x-codex-secondary-used-percent", "20")
resp.Header.Set("x-codex-secondary-window-minutes", "10080")

got := handler.compute429Cooldown(account, []byte(`{"error":{"type":"usage_limit_reached"}}`), resp)
want := 5 * time.Hour
if got != want {
t.Fatalf("cooldown = %v, want %v", got, want)
}
}

func TestCompute429CooldownPlusPrefersExactResetTime(t *testing.T) {
handler := &Handler{}
account := &auth.Account{PlanType: "plus"}
resp := &http.Response{
Header: make(http.Header),
}
resp.Header.Set("x-codex-primary-used-percent", "100")
resp.Header.Set("x-codex-primary-window-minutes", "10080")

got := handler.compute429Cooldown(account, []byte(`{"error":{"type":"usage_limit_reached","resets_in_seconds":1800}}`), resp)
want := 30 * time.Minute
if got != want {
t.Fatalf("cooldown = %v, want %v", got, want)
}
}

func TestAuthMiddlewareSetsAPIKeyContext(t *testing.T) {
gin.SetMode(gin.TestMode)

Expand Down
Loading