This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { buildProject } from "../../../../../lib/build";
|
||||
import { errorResponse } from "../../../../../lib/http";
|
||||
import { touchProject } from "../../../../../lib/storage";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const maxDuration = 60;
|
||||
|
||||
export async function POST(_: Request, context: { params: Promise<{ id: string }> }) {
|
||||
try {
|
||||
const { id } = await context.params;
|
||||
await touchProject(id);
|
||||
const result = await buildProject(id);
|
||||
return NextResponse.json({ report: result.report, previewUrl: `/api/projects/${id}/preview/index.html` });
|
||||
} catch (error) { return errorResponse(error); }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { installProjectDependencies } from "../../../../../../../lib/build";
|
||||
import { errorResponse } from "../../../../../../../lib/http";
|
||||
import { touchProject } from "../../../../../../../lib/storage";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const maxDuration = 120;
|
||||
|
||||
export async function POST(_: Request, context: { params: Promise<{ id: string }> }) {
|
||||
try {
|
||||
const { id } = await context.params;
|
||||
await touchProject(id);
|
||||
return NextResponse.json(await installProjectDependencies(id));
|
||||
} catch (error) { return errorResponse(error); }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { errorResponse } from "../../../../../../lib/http";
|
||||
import { readProjectFile, writeProjectFiles } from "../../../../../../lib/storage";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
type Context = { params: Promise<{ id: string; path: string[] }> };
|
||||
|
||||
export async function GET(_: NextRequest, context: Context) {
|
||||
try {
|
||||
const params = await context.params;
|
||||
return NextResponse.json({ content: await readProjectFile(params.id, params.path) });
|
||||
} catch (error) { return errorResponse(error); }
|
||||
}
|
||||
|
||||
export async function PUT(request: NextRequest, context: Context) {
|
||||
try {
|
||||
const params = await context.params;
|
||||
const body = await request.json();
|
||||
if (typeof body.content !== "string") throw new Error("content must be a string");
|
||||
const project = await writeProjectFiles(params.id, [{ path: params.path.join("/"), content: body.content }], body.revision);
|
||||
return NextResponse.json({ project });
|
||||
} catch (error) { return errorResponse(error); }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { packageProject } from "../../../../../lib/build";
|
||||
import { errorResponse } from "../../../../../lib/http";
|
||||
import { touchProject } from "../../../../../lib/storage";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const maxDuration = 60;
|
||||
|
||||
export async function POST(_: Request, context: { params: Promise<{ id: string }> }) {
|
||||
try {
|
||||
const { id } = await context.params;
|
||||
await touchProject(id);
|
||||
const result = await packageProject(id);
|
||||
return NextResponse.json({ report: result.report, artifactUrl: result.zipPath ? `/api/artifacts/${id}/minitool.zip` : undefined });
|
||||
} catch (error) { return errorResponse(error); }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { errorResponse } from "../../../../../lib/http";
|
||||
import { writeProjectFiles } from "../../../../../lib/storage";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function POST(request: NextRequest, context: { params: Promise<{ id: string }> }) {
|
||||
try {
|
||||
const { id } = await context.params;
|
||||
const body = await request.json();
|
||||
if (!Array.isArray(body.changes) || body.changes.some((item: unknown) => !item || typeof (item as { path?: unknown }).path !== "string" || typeof (item as { content?: unknown }).content !== "string")) throw new Error("changes must contain path and content strings");
|
||||
return NextResponse.json({ project: await writeProjectFiles(id, body.changes, body.revision) });
|
||||
} catch (error) { return errorResponse(error); }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { NextResponse } from "next/server";
|
||||
import { buildProject } from "../../../../../../lib/build";
|
||||
import { errorResponse } from "../../../../../../lib/http";
|
||||
import { projectRoot, touchProject } from "../../../../../../lib/storage";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
const CONTENT_TYPES: Record<string, string> = { ".html": "text/html; charset=utf-8", ".css": "text/css; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".json": "application/json", ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp", ".svg": "image/svg+xml", ".woff": "font/woff", ".woff2": "font/woff2" };
|
||||
|
||||
export async function GET(_: Request, context: { params: Promise<{ id: string; path?: string[] }> }) {
|
||||
try {
|
||||
const params = await context.params;
|
||||
await touchProject(params.id);
|
||||
const segments = params.path?.length ? params.path : ["index.html"];
|
||||
const dist = path.join(projectRoot(params.id), "dist");
|
||||
let target = path.resolve(dist, ...segments);
|
||||
if (!target.startsWith(`${dist}${path.sep}`)) throw new Error("Invalid preview path");
|
||||
try { await fs.access(target); } catch { await buildProject(params.id); target = path.resolve(dist, ...segments); }
|
||||
return new NextResponse(await fs.readFile(target), { headers: { "Content-Type": CONTENT_TYPES[path.extname(target)] || "application/octet-stream", "Cache-Control": "no-store" } });
|
||||
} catch (error) { return errorResponse(error); }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { errorResponse } from "../../../../lib/http";
|
||||
import { getProject, listFiles } from "../../../../lib/storage";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function GET(_: Request, context: { params: Promise<{ id: string }> }) {
|
||||
try {
|
||||
const { id } = await context.params;
|
||||
const [project, files] = await Promise.all([getProject(id), listFiles(id)]);
|
||||
return NextResponse.json({ project, files });
|
||||
} catch (error) { return errorResponse(error); }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { buildProject } from "../../../../../lib/build";
|
||||
import { errorResponse } from "../../../../../lib/http";
|
||||
import { touchProject } from "../../../../../lib/storage";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function POST(_: Request, context: { params: Promise<{ id: string }> }) {
|
||||
try {
|
||||
const { id } = await context.params;
|
||||
await touchProject(id);
|
||||
const result = await buildProject(id);
|
||||
return NextResponse.json({ report: result.report });
|
||||
} catch (error) { return errorResponse(error); }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { createProject, listProjects } from "../../../lib/storage";
|
||||
import { errorResponse } from "../../../lib/http";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function GET() {
|
||||
try { return NextResponse.json({ projects: await listProjects() }); }
|
||||
catch (error) { return errorResponse(error); }
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json().catch(() => ({}));
|
||||
return NextResponse.json({ project: await createProject(body) }, { status: 201 });
|
||||
} catch (error) { return errorResponse(error); }
|
||||
}
|
||||
Reference in New Issue
Block a user