Files

53 lines
1.5 KiB
TypeScript

import { NextResponse } from 'next/server'
import catalogue from '@/lib/data/served.json' with { type: 'json' }
export const revalidate = 3600 // Cache hourly
export async function GET() {
try {
const res = await fetch('https://api.hanzo.ai/v1/models', {
headers: { accept: 'application/json' },
next: { revalidate: 3600 },
})
if (res.ok) {
const data = await res.json()
const list = Array.isArray(data?.data) ? data.data : []
const total = list.length > 0 ? list.length : (catalogue.served?.length ?? 561)
const providers = new Set(list.map((m: any) => m.owned_by).filter(Boolean)).size || 57
return NextResponse.json(
{
totalModels: total,
count: total,
floor: Math.floor(total / 100) * 100,
label: `${Math.floor(total / 100) * 100}+`,
providers,
updated: new Date().toISOString(),
},
{
headers: {
'Cache-Control': 'public, s-maxage=3600, stale-while-revalidate=86400',
},
},
)
}
} catch (_) {}
const fallback = catalogue.served?.length ?? 561
return NextResponse.json(
{
totalModels: fallback,
count: fallback,
floor: Math.floor(fallback / 100) * 100,
label: `${Math.floor(fallback / 100) * 100}+`,
providers: 57,
updated: new Date().toISOString(),
},
{
headers: {
'Cache-Control': 'public, s-maxage=3600, stale-while-revalidate=86400',
},
},
)
}