0520发布文章

This commit is contained in:
zqlit committed 2026-05-21 00:27:35 +08:00
1 parent 347d52d4b8
commit c8cdf9a7bc
90 files changed
+11923 -54

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
import { NextRequest, NextResponse } from "next/server";
import { getLinks, addLink, updateLink, deleteLink, checkLinkViaProxy } from "@/lib/rssapi";
export async function GET(request: NextRequest) {
try {
const { searchParams } = request.nextUrl;
const all = searchParams.get("all") === "1";
const health = searchParams.get("health");
if (health) {
const result = await checkLinkViaProxy(health);
return NextResponse.json(result);
}
const links = await getLinks(all);
return NextResponse.json({ links });
} 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 { name, url, description, hidden } = body;
if (!url) {
return NextResponse.json({ error: "URL is required" }, { status: 400 });
}
await addLink({ name: name || "", url, description, hidden });
return NextResponse.json({ success: true });
} catch (error: unknown) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }
);
}
}
export async function PUT(request: NextRequest) {
try {
const body = await request.json();
const { oldUrl, url: newUrl, name, description, hidden } = body;
if (!oldUrl) {
return NextResponse.json({ error: "oldUrl is required" }, { status: 400 });
}
// If URL changed, delete old and create new
if (newUrl && newUrl !== oldUrl) {
await deleteLink(oldUrl);
await addLink({ name: name || "", url: newUrl, description, hidden });
} else {
const data: Record<string, unknown> = {};
if (name !== undefined) data.name = name;
if (description !== undefined) data.description = description;
if (hidden !== undefined) data.hidden = hidden;
await updateLink(oldUrl, data);
}
return NextResponse.json({ success: true });
} catch (error: unknown) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }
);
}
}
export async function DELETE(request: NextRequest) {
try {
const url = request.nextUrl.searchParams.get("url");
if (!url) {
return NextResponse.json({ error: "URL is required" }, { status: 400 });
}
await deleteLink(url);
return NextResponse.json({ success: true });
} catch (error: unknown) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }
);
}
}