feat: 接入 AnyTLS 节点托管和用户流量同步

This commit is contained in:
2026-09-29 13:35:44 +08:00
parent 586c2399d1
commit ac5fed695c
24 changed files with 1413 additions and 185 deletions
+42
View File
@@ -0,0 +1,42 @@
import { syncAnyTLSNode } from "@/lib/node-agent";
import { ProvisionError } from "@/lib/certificates";
export const runtime = "nodejs";
export async function POST(
request: Request,
context: { params: Promise<{ slug: string }> },
) {
const headers = { "Cache-Control": "no-store" };
try {
const reader = request.body?.getReader();
if (!reader) throw new ProvisionError("缺少报告。");
let length = 0;
const chunks: Uint8Array[] = [];
while (true) {
const { value, done } = await reader.read();
if (done) break;
length += value.byteLength;
if (length > 2 * 1024 * 1024) {
await reader.cancel();
return new Response(null, { status: 413, headers });
}
chunks.push(value);
}
const payload = JSON.parse(Buffer.concat(chunks).toString("utf8"));
return Response.json(
await syncAnyTLSNode(
(await context.params).slug,
request.headers.get("authorization")?.replace(/^Bearer /, "") ?? "",
payload,
),
{ headers },
);
} catch (error) {
return Response.json(
{
error:
error instanceof ProvisionError ? error.message : "节点同步失败。",
},
{ status: error instanceof ProvisionError ? 400 : 500, headers },
);
}
}