3dom4wf7p: Publish public text posts from a feed composer
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
import { SESSION_COOKIE } from "@/lib/cookie";
|
||||
import { createTextPost } from "@/lib/post-create";
|
||||
|
||||
// POST /api/posts { content }
|
||||
// Creates a public text draft on the feed, then publishes it. Returns { id }.
|
||||
// The create call can report status "draft" for a post already on the home
|
||||
// feed, so the browser reloads the first page and confirms the id there.
|
||||
// 401 { error: "sign_in" } without a session.
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const sessionId = req.cookies.get(SESSION_COOKIE)?.value;
|
||||
let content: unknown = null;
|
||||
try {
|
||||
content = ((await req.json()) as { content?: unknown }).content;
|
||||
} catch {
|
||||
content = null;
|
||||
}
|
||||
const result = await createTextPost(sessionId, content);
|
||||
if (!result.ok) {
|
||||
return NextResponse.json({ error: result.error }, { status: result.status });
|
||||
}
|
||||
return NextResponse.json({ id: result.id });
|
||||
}
|
||||
Reference in New Issue
Block a user