18 lines
876 B
TypeScript
18 lines
876 B
TypeScript
import { NextResponse } from 'next/server'
|
|
import { requireDesktop } from '@/lib/desktop-client/service'
|
|
import { DesktopClientError } from '@/lib/desktop-client/contract.mjs'
|
|
import { desktopAgentRules } from '@/lib/desktop-client/agent-rules'
|
|
|
|
export const runtime = 'nodejs'
|
|
export const dynamic = 'force-dynamic'
|
|
const headers = { 'Cache-Control': 'private, no-store', 'X-Content-Type-Options': 'nosniff' }
|
|
export async function GET(request: Request) {
|
|
try {
|
|
await requireDesktop(request)
|
|
return NextResponse.json(desktopAgentRules(new URL(request.url).searchParams.get('binding')), { headers })
|
|
} catch (error) {
|
|
const known = error instanceof DesktopClientError
|
|
return NextResponse.json({ error: known ? error.message : '规则暂时无法读取', code: known ? error.code : 'internal_error' }, { status: known ? error.status : 500, headers })
|
|
}
|
|
}
|