mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-20 08:01:46 +00:00
Load account and API key group selectors through a lightweight admin options endpoint while preserving pagination, filters, disabled groups and revision metadata. Keep aggregate statistics on the group management endpoint. Co-authored-by: Codex <noreply@openai.com>
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import type { AccountGroupRef } from '@/api'
|
|
|
|
import { onMounted, shallowRef } from 'vue'
|
|
import { getAccountGroupOptions } from '@/api'
|
|
import { useRequestState } from './useRequestState'
|
|
|
|
export function useAccountGroupCatalog(options: { immediate?: boolean } = {}) {
|
|
const groups = shallowRef<AccountGroupRef[]>([])
|
|
const request = useRequestState()
|
|
const { loading } = request
|
|
|
|
async function loadGroups() {
|
|
const requestId = request.start()
|
|
const requestOptions = { signal: request.signal }
|
|
try {
|
|
const first = await getAccountGroupOptions({ page: 1, pageSize: 200 }, requestOptions)
|
|
if (!request.isCurrent(requestId))
|
|
return []
|
|
const items = [...first.items]
|
|
for (let page = 2; page <= first.page.totalPages; page += 1) {
|
|
const result = await getAccountGroupOptions({ page, pageSize: first.page.pageSize }, requestOptions)
|
|
if (!request.isCurrent(requestId))
|
|
return []
|
|
items.push(...result.items)
|
|
}
|
|
groups.value = items
|
|
return items
|
|
}
|
|
catch {
|
|
return []
|
|
}
|
|
finally {
|
|
request.finish(requestId)
|
|
}
|
|
}
|
|
|
|
if (options.immediate !== false) {
|
|
onMounted(() => {
|
|
void loadGroups()
|
|
})
|
|
}
|
|
|
|
return {
|
|
groups,
|
|
loading,
|
|
loadGroups,
|
|
}
|
|
}
|