feat: post saving, instant publish, scheduling, post history per channel

This commit is contained in:
Alexey Pavlov
2026-05-31 17:36:02 +03:00
parent e2b64baf2e
commit 1a1eac16ee
5 changed files with 262 additions and 2 deletions
+13
View File
@@ -0,0 +1,13 @@
import { NextResponse } from 'next/server';
import { requireUser } from '@/lib/session';
import { engine } from '@/lib/engine';
export async function POST(req, { params }) {
const user = await requireUser();
if (!user) return NextResponse.json({error:'Unauthorized'},{status:401});
const { id } = await params;
try {
const data = await engine.publishPost(user.id, id);
return NextResponse.json(data);
} catch (e) { return NextResponse.json({error:e.message},{status:500}); }
}
+24
View File
@@ -0,0 +1,24 @@
import { NextResponse } from 'next/server';
import { requireUser } from '@/lib/session';
import { engine } from '@/lib/engine';
export async function PATCH(req, { params }) {
const user = await requireUser();
if (!user) return NextResponse.json({error:'Unauthorized'},{status:401});
const { id } = await params;
const body = await req.json();
try {
const data = await engine.updatePost(user.id, id, body);
return NextResponse.json(data);
} catch (e) { return NextResponse.json({error:e.message},{status:500}); }
}
export async function DELETE(req, { params }) {
const user = await requireUser();
if (!user) return NextResponse.json({error:'Unauthorized'},{status:401});
const { id } = await params;
try {
await engine.deletePost(user.id, id);
return NextResponse.json({ok:true});
} catch (e) { return NextResponse.json({error:e.message},{status:500}); }
}
+25
View File
@@ -0,0 +1,25 @@
import { NextResponse } from 'next/server';
import { requireUser } from '@/lib/session';
import { engine } from '@/lib/engine';
export async function GET(req) {
const user = await requireUser();
if (!user) return NextResponse.json({error:'Unauthorized'},{status:401});
const { searchParams } = new URL(req.url);
const params = {};
for (const [k,v] of searchParams) params[k] = v;
try {
const data = await engine.listUserPosts(user.id, params);
return NextResponse.json(data);
} catch (e) { return NextResponse.json({error:e.message},{status:500}); }
}
export async function POST(req) {
const user = await requireUser();
if (!user) return NextResponse.json({error:'Unauthorized'},{status:401});
const body = await req.json();
try {
const data = await engine.savePost(user.id, body);
return NextResponse.json(data);
} catch (e) { return NextResponse.json({error:e.message},{status:500}); }
}