mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30:23 +08:00
feat: Codex account_name 透传并优化池列表 OAuth 标识与额度重置倒计时展示
(cherry picked from commit 1b9176fc4a)
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import type { OAuthOrganizationInfo } from '@/api/endpoints/types/provider'
|
||||
|
||||
type OAuthIdentityDisplayValue = {
|
||||
oauth_account_name?: string | null
|
||||
oauth_organizations?: OAuthOrganizationInfo[] | null
|
||||
} | null | undefined
|
||||
|
||||
function formatOAuthIdentityShort(
|
||||
value: string | null | undefined,
|
||||
head = 8,
|
||||
@@ -11,24 +16,44 @@ function formatOAuthIdentityShort(
|
||||
return `${normalized.slice(0, head)}...${normalized.slice(-tail)}`
|
||||
}
|
||||
|
||||
function getPrimaryOAuthOrganizationId(
|
||||
value: { oauth_organizations?: OAuthOrganizationInfo[] | null } | null | undefined,
|
||||
): string | null {
|
||||
const organizations = Array.isArray(value?.oauth_organizations) ? value.oauth_organizations : []
|
||||
const defaultOrg = organizations.find(
|
||||
(org) => org?.is_default && typeof org?.id === 'string' && org.id.trim(),
|
||||
)
|
||||
if (defaultOrg?.id) return defaultOrg.id.trim()
|
||||
const firstWithId = organizations.find(
|
||||
(org) => typeof org?.id === 'string' && org.id.trim(),
|
||||
)
|
||||
return firstWithId?.id?.trim() || null
|
||||
function getPrimaryOAuthOrganization(
|
||||
value: OAuthIdentityDisplayValue,
|
||||
): { id: string; title: string } | null {
|
||||
const organizations: OAuthOrganizationInfo[] = Array.isArray(value?.oauth_organizations)
|
||||
? value.oauth_organizations
|
||||
: []
|
||||
let firstWithId: OAuthOrganizationInfo | null = null
|
||||
|
||||
for (let index = 0; index < organizations.length; index += 1) {
|
||||
const org = organizations[index]
|
||||
if (typeof org?.id !== 'string' || !org.id.trim()) continue
|
||||
if (!firstWithId) firstWithId = org
|
||||
if (org.is_default) {
|
||||
firstWithId = org
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (!firstWithId?.id) return null
|
||||
|
||||
return {
|
||||
id: firstWithId.id.trim(),
|
||||
title: typeof firstWithId.title === 'string' ? firstWithId.title.trim() : '',
|
||||
}
|
||||
}
|
||||
|
||||
export function getOAuthOrgBadge(
|
||||
value: { oauth_organizations?: OAuthOrganizationInfo[] | null } | null | undefined,
|
||||
value: OAuthIdentityDisplayValue,
|
||||
): { id: string; label: string } | null {
|
||||
const id = getPrimaryOAuthOrganizationId(value)
|
||||
if (!id) return null
|
||||
return { id, label: formatOAuthIdentityShort(id) }
|
||||
const org = getPrimaryOAuthOrganization(value)
|
||||
if (!org) return null
|
||||
|
||||
const accountName = typeof value?.oauth_account_name === 'string'
|
||||
? value.oauth_account_name.trim()
|
||||
: ''
|
||||
|
||||
return {
|
||||
id: org.id,
|
||||
label: accountName || org.title || formatOAuthIdentityShort(org.id),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user