|
| 1 | +import { ImageResponse } from 'next/og'; |
| 2 | +import { getPriceIndexSnapshot } from '@/lib/api-price-index'; |
| 3 | +import { ogTemplate, OG_SIZE, OG_CONTENT_TYPE } from '@/lib/og-template'; |
| 4 | + |
| 5 | +export const alt = 'AI API Price Index - aiplans.dev'; |
| 6 | +export const size = OG_SIZE; |
| 7 | +export const contentType = OG_CONTENT_TYPE; |
| 8 | +export const revalidate = 21600; |
| 9 | + |
| 10 | +export default async function Image({ |
| 11 | + params, |
| 12 | +}: { |
| 13 | + params: Promise<{ locale: string }>; |
| 14 | +}) { |
| 15 | + const { locale } = await params; |
| 16 | + const isZh = locale === 'zh'; |
| 17 | + const snapshot = await getPriceIndexSnapshot().catch((error: unknown) => { |
| 18 | + console.error('Failed to load API price index stats for Open Graph image', error); |
| 19 | + return null; |
| 20 | + }); |
| 21 | + |
| 22 | + const stats = snapshot |
| 23 | + ? (isZh |
| 24 | + ? [ |
| 25 | + { label: '定价模型', value: snapshot.modelCount.toLocaleString('zh-CN') }, |
| 26 | + { label: '可用渠道', value: snapshot.channelCount.toLocaleString('zh-CN') }, |
| 27 | + { label: '供应商', value: snapshot.providerCount.toLocaleString('zh-CN') }, |
| 28 | + ] |
| 29 | + : [ |
| 30 | + { label: 'Priced models', value: snapshot.modelCount.toLocaleString('en-US') }, |
| 31 | + { label: 'Channels', value: snapshot.channelCount.toLocaleString('en-US') }, |
| 32 | + { label: 'Providers', value: snapshot.providerCount.toLocaleString('en-US') }, |
| 33 | + ]) |
| 34 | + : (isZh |
| 35 | + ? [ |
| 36 | + { label: '价格数据', value: '持续更新' }, |
| 37 | + { label: '供应渠道', value: '多渠道' }, |
| 38 | + { label: '价格来源', value: '可核验' }, |
| 39 | + ] |
| 40 | + : [ |
| 41 | + { label: 'Price data', value: 'Live' }, |
| 42 | + { label: 'Coverage', value: 'Multi-channel' }, |
| 43 | + { label: 'Sources', value: 'Auditable' }, |
| 44 | + ]); |
| 45 | + |
| 46 | + return new ImageResponse( |
| 47 | + ogTemplate({ |
| 48 | + kicker: isZh ? '市场数据报告' : 'Market Data Report', |
| 49 | + title: isZh ? 'AI API 价格指数' : 'AI API Price Index', |
| 50 | + subtitle: isZh |
| 51 | + ? '跨官方、云平台和聚合渠道对比当前 token 价格' |
| 52 | + : 'Current token prices across direct, cloud, and aggregator channels', |
| 53 | + stats, |
| 54 | + accent: '#0f766e', |
| 55 | + locale: isZh ? 'zh' : 'en', |
| 56 | + }), |
| 57 | + size, |
| 58 | + ); |
| 59 | +} |
0 commit comments