feat: export posts and sources

This commit is contained in:
2026-07-19 05:36:52 +08:00
parent 05ddafb0d9
commit 591981b7c8
8 changed files with 50 additions and 7 deletions
+2 -1
View File
@@ -7,8 +7,9 @@ import { requireSameOrigin } from "@/lib/security";
export async function POST(request: Request, { params }: { params: Promise<{ id: string }> }) {
try {
requireSameOrigin(request); const user = await requireUser(); const { id: rawId } = await params; const id = Number(rawId);
const source = db.prepare("SELECT id FROM sources WHERE id=? AND user_id=?").get(id, user.id);
const source = db.prepare("SELECT id,webhook_mode FROM sources WHERE id=? AND user_id=?").get(id, user.id) as { id: number; webhook_mode: string } | undefined;
if (!source) return NextResponse.json({ error: "Not found" }, { status: 404 });
if (source.webhook_mode === "signed") return NextResponse.json({ error: "這個 Webhook 已由 Memos 自動管理;請重新連接來源以重新建立。" }, { status: 409 });
const secret = createWebhookSecret();
db.prepare("UPDATE sources SET webhook_secret_hash=? WHERE id=?").run(webhookSecretHash(secret), id);
const publicOrigin = (process.env.NEXT_PUBLIC_APP_URL || new URL(request.url).origin).replace(/\/$/, "");