36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getLinkPerformance } from '@/lib/analytics';
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
// 获取请求参数
|
|
const { searchParams } = new URL(request.url);
|
|
const linkId = searchParams.get('linkId');
|
|
const startDate = searchParams.get('startDate') || undefined;
|
|
const endDate = searchParams.get('endDate') || undefined;
|
|
|
|
// 验证必要参数
|
|
if (!linkId) {
|
|
return NextResponse.json(
|
|
{ error: 'Missing required parameter: linkId' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
// 获取链接表现数据
|
|
const performanceData = await getLinkPerformance(
|
|
linkId,
|
|
startDate || undefined,
|
|
endDate || undefined
|
|
);
|
|
|
|
// 返回数据
|
|
return NextResponse.json(performanceData);
|
|
} catch (error) {
|
|
console.error('Error in link-performance API:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch link performance data' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|