Unverified Commit 313afe14 authored by Wesley Liddick's avatar Wesley Liddick Committed by GitHub
Browse files

Merge pull request #842 from pkssssss/fix/openai-ws-usage-refresh

fix: 修复 OpenAI WS 用量窗口刷新与限额状态不同步
parents 01180b31 9301dae6
import { describe, expect, it } from 'vitest'
import { buildOpenAIUsageRefreshKey } from '../accountUsageRefresh'
describe('buildOpenAIUsageRefreshKey', () => {
it('会在 codex 快照变化时生成不同 key', () => {
const base = {
id: 1,
platform: 'openai',
type: 'oauth',
updated_at: '2026-03-07T10:00:00Z',
extra: {
codex_usage_updated_at: '2026-03-07T10:00:00Z',
codex_5h_used_percent: 0,
codex_7d_used_percent: 0
}
} as any
const next = {
...base,
extra: {
...base.extra,
codex_usage_updated_at: '2026-03-07T10:01:00Z',
codex_5h_used_percent: 100
}
}
expect(buildOpenAIUsageRefreshKey(base)).not.toBe(buildOpenAIUsageRefreshKey(next))
})
it('非 OpenAI OAuth 账号返回空 key', () => {
expect(buildOpenAIUsageRefreshKey({
id: 2,
platform: 'anthropic',
type: 'oauth',
updated_at: '2026-03-07T10:00:00Z',
extra: {}
} as any)).toBe('')
})
})
import type { Account } from '@/types'
const normalizeUsageRefreshValue = (value: unknown): string => {
if (value == null) return ''
return String(value)
}
export const buildOpenAIUsageRefreshKey = (account: Pick<Account, 'id' | 'platform' | 'type' | 'updated_at' | 'rate_limit_reset_at' | 'extra'>): string => {
if (account.platform !== 'openai' || account.type !== 'oauth') {
return ''
}
const extra = account.extra ?? {}
return [
account.id,
account.updated_at,
account.rate_limit_reset_at,
extra.codex_usage_updated_at,
extra.codex_5h_used_percent,
extra.codex_5h_reset_at,
extra.codex_5h_reset_after_seconds,
extra.codex_5h_window_minutes,
extra.codex_7d_used_percent,
extra.codex_7d_reset_at,
extra.codex_7d_reset_after_seconds,
extra.codex_7d_window_minutes
].map(normalizeUsageRefreshValue).join('|')
}
......@@ -312,6 +312,7 @@ import AccountCapacityCell from '@/components/account/AccountCapacityCell.vue'
import PlatformTypeBadge from '@/components/common/PlatformTypeBadge.vue'
import Icon from '@/components/icons/Icon.vue'
import ErrorPassthroughRulesModal from '@/components/admin/ErrorPassthroughRulesModal.vue'
import { buildOpenAIUsageRefreshKey } from '@/utils/accountUsageRefresh'
import { formatDateTime, formatRelativeTime } from '@/utils/format'
import type { Account, AccountPlatform, AccountType, Proxy, AdminGroup, WindowStats, ClaudeModel } from '@/types'
......@@ -660,7 +661,8 @@ const shouldReplaceAutoRefreshRow = (current: Account, next: Account) => {
current.status !== next.status ||
current.rate_limit_reset_at !== next.rate_limit_reset_at ||
current.overload_until !== next.overload_until ||
current.temp_unschedulable_until !== next.temp_unschedulable_until
current.temp_unschedulable_until !== next.temp_unschedulable_until ||
buildOpenAIUsageRefreshKey(current) !== buildOpenAIUsageRefreshKey(next)
)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment