36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
import JSZip from "jszip";
|
|
import { NextResponse } from "next/server";
|
|
import { auth } from "@/app/(auth)/auth";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
const packageFiles = [
|
|
"package.json", "package-lock.json", "api-client.mjs", "cli.mjs", "mcp-server.mjs",
|
|
"yedir-canvas/SKILL.md", "yedir-canvas/agents/openai.yaml",
|
|
"yedir-canvas/references/operation-protocol.md",
|
|
];
|
|
|
|
export async function GET() {
|
|
const session = await auth();
|
|
if (!session?.user?.id || session.user.type === "guest") {
|
|
return NextResponse.json({ error: "请先登录正式账号" }, { status: 401 });
|
|
}
|
|
const zip = new JSZip();
|
|
const base = path.join(process.cwd(), "integrations", "openclaw");
|
|
try {
|
|
await Promise.all(packageFiles.map(async file => {
|
|
zip.file(`tvstar-mcp/${file}`, await readFile(path.join(base, file)));
|
|
}));
|
|
const archive = await zip.generateAsync({ type: "nodebuffer", compression: "DEFLATE" });
|
|
return new NextResponse(archive, { headers: {
|
|
"Content-Type": "application/zip",
|
|
"Content-Disposition": 'attachment; filename="tvstar-mcp.zip"',
|
|
"Cache-Control": "private, no-store",
|
|
} });
|
|
} catch {
|
|
return NextResponse.json({ error: "插件安装包暂不可用" }, { status: 503 });
|
|
}
|
|
}
|