2026-04-19 15:17:25 +08:00
|
|
|
import { adminWalletApi } from '@/api/admin-wallets'
|
|
|
|
|
import { adminApi } from '@/api/admin'
|
2026-05-13 01:18:38 +08:00
|
|
|
import { adminBillingPlansApi, epayGatewayApi } from '@/api/billing'
|
2026-04-19 15:17:25 +08:00
|
|
|
import { getProvidersSummary } from '@/api/endpoints/providers'
|
|
|
|
|
import { getPoolOverview, getPoolSchedulingPresets, listPoolKeys } from '@/api/endpoints/pool'
|
|
|
|
|
import { listGlobalModels } from '@/api/global-models'
|
2026-05-18 11:03:49 +08:00
|
|
|
import { listRoutingGroups } from '@/api/routing-profiles'
|
2026-04-19 15:17:25 +08:00
|
|
|
import { usersApi } from '@/api/users'
|
|
|
|
|
import { log } from '@/utils/logger'
|
|
|
|
|
|
|
|
|
|
const NAV_DATA_CACHE_TTL_MS = 10 * 1000
|
|
|
|
|
const NAV_SYSTEM_CONFIG_CACHE_TTL_MS = 30 * 1000
|
|
|
|
|
const NAV_POOL_PRESETS_CACHE_TTL_MS = 5 * 60 * 1000
|
|
|
|
|
const PREFETCH_COOLDOWN_MS = 5 * 1000
|
|
|
|
|
|
|
|
|
|
const lastPrefetchAt = new Map<string, number>()
|
|
|
|
|
|
|
|
|
|
const adminRouteWarmers: Record<string, () => Promise<void>> = {
|
|
|
|
|
'/admin/users': async () => {
|
|
|
|
|
await Promise.allSettled([
|
|
|
|
|
import('@/views/admin/Users.vue'),
|
|
|
|
|
usersApi.getAllUsers({ cacheTtlMs: NAV_DATA_CACHE_TTL_MS }),
|
|
|
|
|
adminWalletApi.listAllWallets(
|
|
|
|
|
{ owner_type: 'user' },
|
|
|
|
|
{ cacheTtlMs: NAV_DATA_CACHE_TTL_MS },
|
|
|
|
|
),
|
|
|
|
|
])
|
|
|
|
|
},
|
|
|
|
|
'/admin/providers': async () => {
|
|
|
|
|
await Promise.allSettled([
|
|
|
|
|
import('@/views/admin/ProviderManagement.vue'),
|
|
|
|
|
getProvidersSummary(
|
|
|
|
|
{ page: 1, page_size: 20 },
|
|
|
|
|
{ cacheTtlMs: NAV_DATA_CACHE_TTL_MS },
|
|
|
|
|
),
|
|
|
|
|
adminApi.getSystemConfig('provider_priority_mode', {
|
|
|
|
|
cacheTtlMs: NAV_SYSTEM_CONFIG_CACHE_TTL_MS,
|
|
|
|
|
}),
|
|
|
|
|
listGlobalModels(
|
|
|
|
|
{ is_active: true, limit: 1000 },
|
|
|
|
|
{ cacheTtlMs: NAV_DATA_CACHE_TTL_MS },
|
|
|
|
|
),
|
|
|
|
|
])
|
|
|
|
|
},
|
|
|
|
|
'/admin/models': async () => {
|
|
|
|
|
await Promise.allSettled([
|
|
|
|
|
import('@/views/admin/ModelManagement.vue'),
|
|
|
|
|
listGlobalModels(
|
|
|
|
|
{ skip: 0, limit: 20 },
|
|
|
|
|
{ cacheTtlMs: NAV_DATA_CACHE_TTL_MS },
|
|
|
|
|
),
|
|
|
|
|
])
|
|
|
|
|
},
|
2026-05-18 11:03:49 +08:00
|
|
|
'/admin/routing': async () => {
|
|
|
|
|
await Promise.allSettled([
|
|
|
|
|
import('@/views/admin/RoutingProfiles.vue'),
|
|
|
|
|
listRoutingGroups(),
|
|
|
|
|
])
|
|
|
|
|
},
|
2026-04-19 15:17:25 +08:00
|
|
|
'/admin/pool': async () => {
|
|
|
|
|
const [overviewResult] = await Promise.allSettled([
|
|
|
|
|
getPoolOverview({ cacheTtlMs: NAV_DATA_CACHE_TTL_MS }),
|
|
|
|
|
getPoolSchedulingPresets({ cacheTtlMs: NAV_POOL_PRESETS_CACHE_TTL_MS }),
|
|
|
|
|
import('@/views/admin/PoolManagement.vue'),
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
if (overviewResult.status !== 'fulfilled') {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const firstProviderId = overviewResult.value.items.find(item => item.pool_enabled)?.provider_id
|
|
|
|
|
if (!firstProviderId) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await listPoolKeys(
|
|
|
|
|
firstProviderId,
|
|
|
|
|
{ page: 1, page_size: 50, status: 'all' },
|
|
|
|
|
{ cacheTtlMs: NAV_DATA_CACHE_TTL_MS },
|
|
|
|
|
)
|
|
|
|
|
},
|
2026-05-13 01:18:38 +08:00
|
|
|
'/admin/payment-gateways': async () => {
|
|
|
|
|
await Promise.allSettled([
|
|
|
|
|
import('@/views/admin/PaymentGatewaySettings.vue'),
|
|
|
|
|
epayGatewayApi.get(),
|
|
|
|
|
])
|
|
|
|
|
},
|
|
|
|
|
'/admin/billing-plans': async () => {
|
|
|
|
|
await Promise.allSettled([
|
|
|
|
|
import('@/views/admin/BillingPlansManagement.vue'),
|
|
|
|
|
adminBillingPlansApi.list(),
|
|
|
|
|
])
|
|
|
|
|
},
|
2026-04-19 15:17:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function prefetchAdminNavigationTarget(href: string): void {
|
|
|
|
|
const warmer = adminRouteWarmers[href]
|
|
|
|
|
if (!warmer) return
|
|
|
|
|
|
|
|
|
|
const now = Date.now()
|
|
|
|
|
const lastRun = lastPrefetchAt.get(href) ?? 0
|
|
|
|
|
if (now - lastRun < PREFETCH_COOLDOWN_MS) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
lastPrefetchAt.set(href, now)
|
|
|
|
|
|
|
|
|
|
void warmer().catch((err) => {
|
|
|
|
|
log.debug('[adminNavigationPrefetch] ignore prefetch failure', err)
|
|
|
|
|
})
|
|
|
|
|
}
|