3dom4wf7p: Publish public text posts from a feed composer

This commit is contained in:
2026-10-19 14:19:12 -06:00
parent 28037a2849
commit de535a500d
8 changed files with 404 additions and 0 deletions
+26
View File
@@ -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 });
}
+5
View File
@@ -42,3 +42,8 @@ button:disabled { opacity: .5; cursor: not-allowed; }
.like-btn:disabled:not(.liked) { color: var(--grey); }
.like-error { color: #a8141b; font-size: 13px; align-self: center; }
.post-stats { align-items: center; }
.composer { background: #fff; border: 1px solid var(--line); border-radius: 0; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.composer-label { margin: 0; }
.composer textarea { font: inherit; width: 100%; padding: 12px; border: 1px solid #999; border-radius: 0; resize: vertical; background: #fff; color: var(--ink); }
.composer textarea:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.composer .composer-post { align-self: flex-end; margin: 0; padding: 10px 24px; border-radius: 0; }