feat: complete marketing command center with pipeline, UI, and asset generation
- Dashboard with campaign management, asset gallery, and publishing queue - 7-agent pipeline: trend scout, research, scripts, ad creative, video, copy, distribution - Campaign form with screenshot upload, goal picker, platform selection - Campaign detail view with Details/Pipeline/Assets/Chat tabs - Two-set image generation: Gemini AI (NanoBanana MCP) + Canvas Design posters - Remotion video rendering with phone.png frame and real screenshot alignment - honeyDue branding: blue #0079FF, orange #FF9400, Inter font, warm off-white - Asset cards with source badges (Gemini/Canvas/Remotion/Playwright) - Markdown/JSON render endpoint for viewing pipeline outputs as HTML - Settings page with Tavily, Gemini, Postiz, Nextdoor integration management - Claude Chat for campaign feedback loop with streaming SSE - Postiz publishing modal with scheduling - Auth with NextAuth credentials + JWT sessions - SQLite via Prisma with better-sqlite3 adapter Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import { readFile, stat } from "fs/promises";
|
||||
import path from "path";
|
||||
import { auth } from "@/lib/auth";
|
||||
|
||||
const PIPELINE_ROOT = process.env.PIPELINE_ROOT || path.join(process.cwd(), "pipeline");
|
||||
|
||||
const CONTENT_TYPES: Record<string, string> = {
|
||||
".png": "image/png",
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".gif": "image/gif",
|
||||
".webp": "image/webp",
|
||||
".mp4": "video/mp4",
|
||||
".webm": "video/webm",
|
||||
".html": "text/html",
|
||||
".json": "application/json",
|
||||
".md": "text/markdown",
|
||||
".txt": "text/plain",
|
||||
".css": "text/css",
|
||||
".js": "text/javascript",
|
||||
".svg": "image/svg+xml",
|
||||
};
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ path: string[] }> }
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session) {
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
|
||||
const { path: segments } = await params;
|
||||
const filePath = path.join(PIPELINE_ROOT, ...segments);
|
||||
|
||||
// Security: prevent path traversal
|
||||
const resolved = path.resolve(filePath);
|
||||
if (!resolved.startsWith(path.resolve(PIPELINE_ROOT))) {
|
||||
return new Response("Forbidden", { status: 403 });
|
||||
}
|
||||
|
||||
try {
|
||||
const fileStat = await stat(resolved);
|
||||
const ext = path.extname(resolved).toLowerCase();
|
||||
const contentType = CONTENT_TYPES[ext] || "application/octet-stream";
|
||||
const fileSize = fileStat.size;
|
||||
|
||||
// Handle range requests (needed for video seeking/thumbnails)
|
||||
const range = request.headers.get("range");
|
||||
if (range) {
|
||||
const match = range.match(/bytes=(\d+)-(\d*)/);
|
||||
if (match) {
|
||||
const start = parseInt(match[1], 10);
|
||||
const end = match[2] ? parseInt(match[2], 10) : fileSize - 1;
|
||||
const buffer = await readFile(resolved);
|
||||
const chunk = buffer.subarray(start, end + 1);
|
||||
|
||||
return new Response(chunk, {
|
||||
status: 206,
|
||||
headers: {
|
||||
"Content-Type": contentType,
|
||||
"Content-Range": `bytes ${start}-${end}/${fileSize}`,
|
||||
"Content-Length": String(chunk.length),
|
||||
"Accept-Ranges": "bytes",
|
||||
"Cache-Control": "no-cache",
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const buffer = await readFile(resolved);
|
||||
return new Response(buffer, {
|
||||
headers: {
|
||||
"Content-Type": contentType,
|
||||
"Content-Length": String(fileSize),
|
||||
"Accept-Ranges": "bytes",
|
||||
"Cache-Control": "no-cache",
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
return new Response("Not found", { status: 404 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import { readFile } from "fs/promises";
|
||||
import path from "path";
|
||||
import { auth } from "@/lib/auth";
|
||||
|
||||
const PIPELINE_ROOT =
|
||||
process.env.PIPELINE_ROOT || path.join(process.cwd(), "pipeline");
|
||||
|
||||
function markdownToHtml(md: string): string {
|
||||
let html = md
|
||||
// Headers
|
||||
.replace(/^#{6}\s+(.+)$/gm, "<h6>$1</h6>")
|
||||
.replace(/^#{5}\s+(.+)$/gm, "<h5>$1</h5>")
|
||||
.replace(/^#{4}\s+(.+)$/gm, "<h4>$1</h4>")
|
||||
.replace(/^###\s+(.+)$/gm, "<h3>$1</h3>")
|
||||
.replace(/^##\s+(.+)$/gm, "<h2>$1</h2>")
|
||||
.replace(/^#\s+(.+)$/gm, "<h1>$1</h1>")
|
||||
// Bold and italic
|
||||
.replace(/\*\*\*(.+?)\*\*\*/g, "<strong><em>$1</em></strong>")
|
||||
.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>")
|
||||
.replace(/\*(.+?)\*/g, "<em>$1</em>")
|
||||
// Code blocks
|
||||
.replace(/```(\w*)\n([\s\S]*?)```/g, "<pre><code>$2</code></pre>")
|
||||
// Inline code
|
||||
.replace(/`([^`]+)`/g, "<code>$1</code>")
|
||||
// Unordered lists
|
||||
.replace(/^[-*]\s+(.+)$/gm, "<li>$1</li>")
|
||||
// Ordered lists
|
||||
.replace(/^\d+\.\s+(.+)$/gm, "<li>$1</li>")
|
||||
// Horizontal rules
|
||||
.replace(/^---+$/gm, "<hr>")
|
||||
// Line breaks to paragraphs
|
||||
.replace(/\n\n+/g, "</p><p>")
|
||||
// Single newlines in context
|
||||
.replace(/\n/g, "<br>");
|
||||
|
||||
// Wrap consecutive <li> in <ul>
|
||||
html = html.replace(/((?:<li>.*?<\/li><br>?)+)/g, "<ul>$1</ul>");
|
||||
|
||||
// Tables
|
||||
html = html.replace(
|
||||
/\|(.+)\|\n\|[-| :]+\|\n((?:\|.+\|\n?)+)/g,
|
||||
(_match, header: string, body: string) => {
|
||||
const ths = header
|
||||
.split("|")
|
||||
.filter((c: string) => c.trim())
|
||||
.map((c: string) => `<th>${c.trim()}</th>`)
|
||||
.join("");
|
||||
const rows = body
|
||||
.trim()
|
||||
.split("\n")
|
||||
.map((row: string) => {
|
||||
const tds = row
|
||||
.split("|")
|
||||
.filter((c: string) => c.trim())
|
||||
.map((c: string) => `<td>${c.trim()}</td>`)
|
||||
.join("");
|
||||
return `<tr>${tds}</tr>`;
|
||||
})
|
||||
.join("");
|
||||
return `<table><thead><tr>${ths}</tr></thead><tbody>${rows}</tbody></table>`;
|
||||
}
|
||||
);
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Inter', sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 40px auto;
|
||||
padding: 0 20px;
|
||||
color: #1a1a2e;
|
||||
line-height: 1.7;
|
||||
background: #f8f6f2;
|
||||
}
|
||||
h1 { font-size: 2em; border-bottom: 2px solid #0079FF; padding-bottom: 8px; color: #0079FF; }
|
||||
h2 { font-size: 1.5em; margin-top: 2em; color: #1a1a2e; }
|
||||
h3 { font-size: 1.2em; color: #555; }
|
||||
code { background: #e8e8e8; padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
|
||||
pre { background: #1a1a2e; color: #e8e8e8; padding: 16px; border-radius: 8px; overflow-x: auto; }
|
||||
pre code { background: none; padding: 0; }
|
||||
table { border-collapse: collapse; width: 100%; margin: 1em 0; }
|
||||
th, td { border: 1px solid #ddd; padding: 8px 12px; text-align: left; }
|
||||
th { background: #0079FF; color: white; }
|
||||
tr:nth-child(even) { background: #f0f0f0; }
|
||||
hr { border: none; border-top: 1px solid #ddd; margin: 2em 0; }
|
||||
ul { padding-left: 1.5em; }
|
||||
li { margin: 4px 0; }
|
||||
strong { color: #0079FF; }
|
||||
a { color: #0079FF; }
|
||||
</style>
|
||||
</head>
|
||||
<body><p>${html}</p></body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ path: string[] }> }
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session) return new Response("Unauthorized", { status: 401 });
|
||||
|
||||
const { path: segments } = await params;
|
||||
const filePath = path.join(PIPELINE_ROOT, ...segments);
|
||||
|
||||
const resolved = path.resolve(filePath);
|
||||
if (!resolved.startsWith(path.resolve(PIPELINE_ROOT))) {
|
||||
return new Response("Forbidden", { status: 403 });
|
||||
}
|
||||
|
||||
try {
|
||||
const content = await readFile(resolved, "utf-8");
|
||||
const ext = path.extname(resolved).toLowerCase();
|
||||
|
||||
if (ext === ".md") {
|
||||
return new Response(markdownToHtml(content), {
|
||||
headers: { "Content-Type": "text/html; charset=utf-8" },
|
||||
});
|
||||
}
|
||||
|
||||
if (ext === ".json") {
|
||||
const pretty = JSON.stringify(JSON.parse(content), null, 2);
|
||||
return new Response(
|
||||
`<!DOCTYPE html><html><head><meta charset="utf-8"><style>body{font-family:monospace;max-width:900px;margin:40px auto;padding:0 20px;background:#1a1a2e;color:#e8e8e8;}</style></head><body><pre>${pretty.replace(/</g, "<")}</pre></body></html>`,
|
||||
{ headers: { "Content-Type": "text/html; charset=utf-8" } }
|
||||
);
|
||||
}
|
||||
|
||||
// HTML files served as-is
|
||||
if (ext === ".html") {
|
||||
return new Response(content, {
|
||||
headers: { "Content-Type": "text/html; charset=utf-8" },
|
||||
});
|
||||
}
|
||||
|
||||
// Fallback: plain text
|
||||
return new Response(content, {
|
||||
headers: { "Content-Type": "text/plain; charset=utf-8" },
|
||||
});
|
||||
} catch {
|
||||
return new Response("Not found", { status: 404 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user