This commit is contained in:
Vaica committed 2026-06-21 23:28:31 +08:00
1 parent 834d9d0425
commit 424355da7c
6 files changed
+220 -32

No files matched your search

-12
View File
@@ -1,18 +1,9 @@
import { NextRequest, NextResponse } from "next/server";
import { listPosts, createPost, getPostCount } from "@/lib/posts";
import { cleanExpired } from "@/lib/recycle";
import { CONTENT_DIR, BLOG_ROOT } from "@/lib/config";
import fs from "fs";
export async function GET(request: NextRequest) {
try {
// Debug logging
console.log("[api/posts] BLOG_ROOT:", BLOG_ROOT);
console.log("[api/posts] CONTENT_DIR:", CONTENT_DIR);
console.log("[api/posts] cwd:", process.cwd());
console.log("[api/posts] env BLOG_ROOT:", process.env.BLOG_ROOT);
console.log("[api/posts] CONTENT_DIR exists:", fs.existsSync(CONTENT_DIR));
cleanExpired(); // housekeeping on each request
const { searchParams } = request.nextUrl;
@@ -24,11 +15,8 @@ export async function GET(request: NextRequest) {
const result = listPosts({ search, page, perPage, includeDrafts });
const totalCount = getPostCount();
console.log("[api/posts] result:", result.total, "posts");
return NextResponse.json({ ...result, totalCount });
} catch (error: unknown) {
console.error("[api/posts] error:", error);
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }