route.js 1.1 KB

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