80a1ffbe4d
Apps share the same backend, API keys, and publishing flow but each gets its own branding (name, colors, icon, app URL), knowledge files (brand identity, product info, platform guidelines), and campaigns. The pipeline dynamically writes _knowledge/ files and copies app assets before each run. - Add App model with slug, colors, appUrl, and knowledge markdown fields - Add appId FK to Campaign, seed honeyDue as first app with existing knowledge - App switcher dropdown in sidebar with icon previews - Filter campaigns, stats, and assets by active app (cookie-based) - De-hardcode lib/claude.ts: AppConfig interface, templated prompts, dynamic _knowledge/ and Remotion asset copying - App management pages (list, create, edit) with icon upload and color pickers - Asset library sort options (newest, oldest, name, platform, type) - Asset cards show creation date - Remotion HoneyDueAd accepts colors/appName props Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import { auth } from "@/lib/auth";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { writeFile, mkdir } from "fs/promises";
|
|
import path from "path";
|
|
|
|
const PIPELINE_ROOT = process.env.PIPELINE_ROOT || path.join(process.cwd(), "pipeline");
|
|
|
|
export async function POST(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ slug: string }> }
|
|
) {
|
|
const session = await auth();
|
|
if (!session) return new Response("Unauthorized", { status: 401 });
|
|
|
|
const { slug } = await params;
|
|
const app = await prisma.app.findUnique({ where: { slug } });
|
|
if (!app) return Response.json({ error: "App not found" }, { status: 404 });
|
|
|
|
const formData = await request.formData();
|
|
const type = formData.get("type") as string; // "icon", "phone", or "screenshot"
|
|
const file = formData.get("file") as File | null;
|
|
|
|
if (!file || !file.type.startsWith("image/")) {
|
|
return Response.json({ error: "No valid image file provided" }, { status: 400 });
|
|
}
|
|
|
|
const appDir = path.join(PIPELINE_ROOT, "apps", slug);
|
|
const buffer = Buffer.from(await file.arrayBuffer());
|
|
|
|
if (type === "icon" || type === "phone") {
|
|
const filePath = path.join(appDir, `${type}.png`);
|
|
await mkdir(appDir, { recursive: true });
|
|
await writeFile(filePath, buffer);
|
|
return Response.json({ path: `apps/${slug}/${type}.png` });
|
|
}
|
|
|
|
if (type === "screenshot") {
|
|
const screenshotsDir = path.join(appDir, "screenshots");
|
|
await mkdir(screenshotsDir, { recursive: true });
|
|
const fileName = file.name || "screenshot.png";
|
|
const filePath = path.join(screenshotsDir, fileName);
|
|
await writeFile(filePath, buffer);
|
|
return Response.json({ path: `apps/${slug}/screenshots/${fileName}` });
|
|
}
|
|
|
|
return Response.json({ error: "Invalid type. Use: icon, phone, or screenshot" }, { status: 400 });
|
|
}
|