feat: implement AGB History with dynamic CMS fetching

This commit is contained in:
2026-04-27 12:11:11 +02:00
parent 24a19adf19
commit 909bad573b
7 changed files with 181 additions and 2 deletions

View File

@@ -11,8 +11,38 @@ export async function GET(req: NextRequest, { params }: { params: Promise<{ slug
try {
const { slug } = await params;
// Hardcoded bypass for AGBs to use the original uploaded PDF.
// Handle AGBs specifically - either fetch from collection or use fallback file
if (slug === 'agbs') {
const payload = await getPayload({ config: configPromise });
const currentAgbs = await payload.find({
collection: 'agbs-collection',
where: {
isCurrent: { equals: true },
},
limit: 1,
});
if (currentAgbs.totalDocs > 0) {
const agb = currentAgbs.docs[0];
const media = agb.file as any;
if (media && media.url) {
// If it's a remote URL or absolute path, we might need to fetch it
// For now assume it's a local file in public/media
const filePath = path.join(process.cwd(), 'public', media.url);
if (fs.existsSync(filePath)) {
const fileBuffer = fs.readFileSync(filePath);
return new NextResponse(fileBuffer, {
status: 200,
headers: {
'Content-Type': 'application/pdf',
'Content-Disposition': `attachment; filename="${media.filename}"`,
},
});
}
}
}
// Fallback for hardcoded legacy AGB
const filePath = path.join(process.cwd(), 'public', 'AVB-KLZ-4-2026.pdf');
if (fs.existsSync(filePath)) {
const fileBuffer = fs.readFileSync(filePath);