/** * 代理路由:/api/assets/tickets * 将请求转发至 issue-ai 的 /api/tickets/by-asset API * * GET /api/assets/tickets?deviceIp=xxx&deviceSn=xxx * * 环境变量: * ISSUE_API_URL — issue-ai API 地址(默认 http://localhost:6176/api) * ISSUE_API_KEY — API 密钥 */ import { NextRequest, NextResponse } from 'next/server' import { getTicketsByAsset } from '@/lib/issue-client' export async function GET(request: NextRequest) { const { searchParams } = new URL(request.url) const deviceIp = searchParams.get('deviceIp') || undefined const deviceSn = searchParams.get('deviceSn') || undefined if (!deviceIp && !deviceSn) { return NextResponse.json( { error: '缺少必要参数:deviceIp 或 deviceSn' }, { status: 400 } ) } try { // 转发用户 cookie 用于 issue-ai 认证 const cookie = request.headers.get('cookie') || undefined const result = await getTicketsByAsset({ ip: deviceIp, sn: deviceSn, cookie, }) return NextResponse.json(result) } catch (err: unknown) { const message = err instanceof Error ? err.message : '获取工单列表失败' const cause = err instanceof Error ? err.cause : undefined console.error('[/api/assets/tickets]', message, cause) return NextResponse.json({ error: message, detail: String(cause) }, { status: 502 }) } }