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>
91 lines
2.7 KiB
TypeScript
91 lines
2.7 KiB
TypeScript
import { auth } from "@/lib/auth";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { buildCampaignPrompt, launchPipeline, type AppConfig } from "@/lib/claude";
|
|
import path from "path";
|
|
import { mkdirSync } from "fs";
|
|
|
|
export async function POST(
|
|
_request: Request,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
const session = await auth();
|
|
if (!session) return new Response("Unauthorized", { status: 401 });
|
|
|
|
const { id } = await params;
|
|
|
|
const campaign = await prisma.campaign.findUnique({
|
|
where: { id },
|
|
include: { app: true },
|
|
});
|
|
if (!campaign) {
|
|
return Response.json({ error: "Not found" }, { status: 404 });
|
|
}
|
|
|
|
if (campaign.status !== "draft") {
|
|
return Response.json(
|
|
{ error: "Campaign is not in draft status" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
// Build AppConfig from the campaign's app
|
|
let appConfig: AppConfig | undefined;
|
|
if (campaign.app) {
|
|
const app = campaign.app;
|
|
appConfig = {
|
|
name: app.name,
|
|
slug: app.slug,
|
|
primaryColor: app.primaryColor,
|
|
accentColor: app.accentColor,
|
|
darkBg: app.darkBg,
|
|
assetsDir: `apps/${app.slug}`,
|
|
brandIdentity: app.brandIdentity,
|
|
productInfo: app.productInfo,
|
|
platformGuidelines: app.platformGuidelines,
|
|
};
|
|
}
|
|
|
|
const config = campaign.config ? JSON.parse(campaign.config) : {};
|
|
const pipelineRoot =
|
|
process.env.PIPELINE_ROOT || path.join(process.cwd(), "pipeline");
|
|
|
|
const dateStr = new Date().toISOString().slice(0, 10).replace(/-/g, "");
|
|
const taskName = campaign.name.replace(/\s+/g, "_").toLowerCase();
|
|
const outputPath = `outputs/${taskName}_${dateStr}`;
|
|
|
|
// Create output directories
|
|
const dirs = ["ads", "scripts", "video", "copy"];
|
|
for (const dir of dirs) {
|
|
mkdirSync(path.join(pipelineRoot, outputPath, dir), { recursive: true });
|
|
}
|
|
|
|
const prompt = buildCampaignPrompt(
|
|
{
|
|
name: campaign.name,
|
|
platforms: JSON.parse(campaign.platforms),
|
|
goal: config.goal || "brand awareness",
|
|
keyMessage: config.keyMessage || campaign.name,
|
|
socialProof: config.socialProof,
|
|
targetAudience: config.targetAudience,
|
|
visualDirection: config.visualDirection,
|
|
competitorApps: config.competitorApps,
|
|
variations: config.variations,
|
|
useTrendReport: config.useTrendReport,
|
|
screenshots: config.screenshots,
|
|
},
|
|
appConfig
|
|
);
|
|
|
|
await prisma.campaign.update({
|
|
where: { id },
|
|
data: { prompt, outputPath },
|
|
});
|
|
|
|
// Launch pipeline asynchronously — don't await
|
|
launchPipeline(id, prompt, pipelineRoot, appConfig).catch((err) =>
|
|
console.error(`Pipeline failed for campaign ${id}:`, err)
|
|
);
|
|
|
|
return Response.json({ status: "launched", outputPath });
|
|
}
|