Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions apps/site/src/app/api/apps/assets/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { NextResponse } from "next/server";

import { getFile } from "@/lib/prisma-apps-github";

const MIME_TYPES: Record<string, string> = {
".png": "image/png",
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".webp": "image/webp",
".gif": "image/gif",
".svg": "image/svg+xml",
".json": "application/json",
};

function getMimeType(path: string) {
const extension = path.slice(path.lastIndexOf(".")).toLowerCase();
return MIME_TYPES[extension] ?? "application/octet-stream";
}

export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const path = searchParams.get("path")?.trim();

if (!path) {
return NextResponse.json(
{
error: "missing_path",
message: "Expected a repo-relative asset path.",
},
{ status: 400 },
);
}

const file = await getFile(path);

if (!file) {
return NextResponse.json(
{
error: "asset_not_found",
message: `No asset found for "${path}".`,
},
{ status: 404 },
);
}

if (file.encoding !== "base64") {
return NextResponse.json(
{
error: "unsupported_encoding",
message: `Unsupported asset encoding "${file.encoding}".`,
},
{ status: 500 },
);
}

return new NextResponse(Buffer.from(file.content, "base64"), {
headers: {
"Content-Type": getMimeType(file.path),
"Cache-Control": "public, s-maxage=300, stale-while-revalidate=86400",
},
});
}
51 changes: 51 additions & 0 deletions apps/site/src/app/api/apps/deploy/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { getAppBySlug } from "@/data/apps";
import { NextResponse } from "next/server";

export async function POST(request: Request) {
let slug: string | undefined;

try {
const body = (await request.json()) as { slug?: string };
slug = body.slug;
} catch {
return NextResponse.json(
{
error: "invalid_request",
message: "Expected a JSON body with an app slug.",
},
{ status: 400 },
);
}

if (!slug) {
return NextResponse.json(
{
error: "missing_slug",
message: "Missing app slug.",
},
{ status: 400 },
);
}

const app = getAppBySlug(slug);
if (!app) {
return NextResponse.json(
{
error: "app_not_found",
message: `No app listing found for "${slug}".`,
},
{ status: 404 },
);
}

return NextResponse.json(
{
status: "pending_integration",
slug: app.slug,
appName: app.name,
message:
"The Prisma Compute deploy API is not wired yet. This endpoint is the planned integration seam for one-click app deployment.",
},
{ status: 501 },
);
}
Loading
Loading