route.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { NextResponse } from "next/server";
  2. import { listFiles } from "@/lib/storage";
  3. /**
  4. * GET /api/files?branch=&year=&month=&day=
  5. *
  6. * Returns the list of PDF files for a specific branch + date.
  7. * Example:
  8. * /api/files?branch=NL01&year=2024&month=10&day=23
  9. */
  10. export async function GET(request) {
  11. const { searchParams } = new URL(request.url);
  12. const branch = searchParams.get("branch");
  13. const year = searchParams.get("year");
  14. const month = searchParams.get("month");
  15. const day = searchParams.get("day");
  16. console.log("[/api/files] query:", { branch, year, month, day });
  17. // Validate required query params
  18. if (!branch || !year || !month || !day) {
  19. return NextResponse.json(
  20. { error: "branch, year, month, day sind erforderlich" },
  21. { status: 400 }
  22. );
  23. }
  24. try {
  25. const files = await listFiles(branch, year, month, day);
  26. return NextResponse.json({ branch, year, month, day, files });
  27. } catch (error) {
  28. console.error("[/api/files] Error:", error);
  29. return NextResponse.json(
  30. { error: "Fehler beim Lesen der Dateien: " + error.message },
  31. { status: 500 }
  32. );
  33. }
  34. }