added:增加Linux-server

This commit is contained in:
Vaica committed 2026-06-21 20:42:44 +08:00
1 parent 6fe4e9d23f
commit d78f3f811b
90 files changed
+16784 -1

No files matched your search

@@ -0,0 +1,65 @@
import { NextRequest, NextResponse } from "next/server";
import { getPost, updatePost } from "@/lib/posts";
import { moveToRecycle } from "@/lib/recycle";
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ slug: string }> }
) {
try {
const { slug } = await params;
const post = getPost(slug);
if (!post) {
return NextResponse.json({ error: "Post not found" }, { status: 404 });
}
return NextResponse.json(post);
} catch (error: unknown) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }
);
}
}
export async function PUT(
request: NextRequest,
{ params }: { params: Promise<{ slug: string }> }
) {
try {
const { slug } = await params;
const body = await request.json();
const { frontMatter, content } = body;
const result = updatePost(slug, frontMatter || {}, content);
if (!result.success) {
return NextResponse.json({ error: "Post not found" }, { status: 404 });
}
return NextResponse.json({ success: true, dirPath: result.dirPath });
} catch (error: unknown) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }
);
}
}
export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ slug: string }> }
) {
try {
const { slug } = await params;
const post = getPost(slug);
if (!post) {
return NextResponse.json({ error: "Post not found" }, { status: 404 });
}
moveToRecycle(slug, post.dirPath, post.frontMatter.title);
return NextResponse.json({ success: true });
} catch (error: unknown) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }
);
}
}
@@ -0,0 +1,46 @@
import { NextRequest, NextResponse } from "next/server";
import { updatePost, listPosts, getPost } from "@/lib/posts";
export async function PUT(request: NextRequest) {
try {
const body = await request.json();
const { slugs, action, categories, tags, draft } = body;
if (!slugs || !Array.isArray(slugs) || slugs.length === 0) {
return NextResponse.json({ error: "slugs array required" }, { status: 400 });
}
const results: string[] = [];
for (const slug of slugs) {
const post = getPost(String(slug));
if (!post) { results.push(`Not found: ${slug}`); continue; }
const updates: Record<string, unknown> = {};
if (action === "categories" && categories !== undefined) {
updates.categories = categories;
} else if (action === "tags" && tags !== undefined) {
updates.tags = tags;
} else if (action === "draft" && draft !== undefined) {
updates.draft = draft;
} else if (action === "all") {
if (categories !== undefined) updates.categories = categories;
if (tags !== undefined) updates.tags = tags;
if (draft !== undefined) updates.draft = draft;
}
if (Object.keys(updates).length === 0) {
return NextResponse.json({ error: "No valid updates" }, { status: 400 });
}
updatePost(String(slug), updates);
results.push(`Updated: ${slug}`);
}
return NextResponse.json({ success: true, results });
} catch (error: unknown) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }
);
}
}
+47
View File
@@ -0,0 +1,47 @@
import { NextRequest, NextResponse } from "next/server";
import { listPosts, createPost, getPostCount } from "@/lib/posts";
import { cleanExpired } from "@/lib/recycle";
export async function GET(request: NextRequest) {
try {
cleanExpired(); // housekeeping on each request
const { searchParams } = request.nextUrl;
const search = searchParams.get("search") || "";
const page = parseInt(searchParams.get("page") || "1", 10);
const perPage = parseInt(searchParams.get("perPage") || "20", 10);
const includeDrafts = searchParams.get("includeDrafts") !== "false";
const result = listPosts({ search, page, perPage, includeDrafts });
const totalCount = getPostCount();
return NextResponse.json({ ...result, totalCount });
} catch (error: unknown) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }
);
}
}
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { frontMatter, content } = body;
if (!frontMatter?.title || !frontMatter?.slug) {
return NextResponse.json(
{ error: "Title and slug are required" },
{ status: 400 }
);
}
const dirPath = createPost(frontMatter, content || "");
return NextResponse.json({ success: true, dirPath }, { status: 201 });
} catch (error: unknown) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }
);
}
}