import { getBookRepository } from "@/lib/server/app-services";

export async function GET(request: Request) {
  try {
    const query = new URL(request.url).searchParams.get("q") ?? "";
    return Response.json({ books: await getBookRepository().list(query) });
  } catch {
    return Response.json(
      { error: { code: "library_unavailable", message: "书架暂时无法加载。" } },
      { status: 500 },
    );
  }
}
