Files
hy2-panel/app/api/install/sing-box/[arch]/route.ts
T

40 lines
1.1 KiB
TypeScript

import { readFile } from "node:fs/promises";
import path from "node:path";
import { SING_BOX_VERSION } from "@/lib/anytls";
import { createHash } from "node:crypto";
export const runtime = "nodejs";
export async function GET(
request: Request,
context: { params: Promise<{ arch: string }> },
) {
const { arch } = await context.params;
if (!["amd64", "arm64"].includes(arch))
return new Response(null, { status: 404 });
try {
const bytes = await readFile(
path.join(
process.cwd(),
"data/artifacts",
`sing-box-${SING_BOX_VERSION}-linux-${arch}`,
),
);
const checksum = createHash("sha256").update(bytes).digest("hex");
if (new URL(request.url).searchParams.has("sha256"))
return new Response(checksum, {
headers: { "Cache-Control": "no-store" },
});
return new Response(bytes, {
headers: {
"Content-Type": "application/octet-stream",
"Cache-Control": "no-store",
"X-Content-SHA256": checksum,
},
});
} catch {
return new Response(
"尚未构建节点程序,请运行 scripts/build-sing-box.sh。",
{ status: 503 },
);
}
}