Form implementation, api routes

This commit is contained in:
2024-09-26 16:04:57 -04:00
parent 66137ff7b4
commit 6584a48f27
23 changed files with 663 additions and 214 deletions

View File

@@ -0,0 +1,26 @@
import { NextRequest, NextResponse } from 'next/server';
import path from 'path';
import fs from 'fs/promises';
import { auth } from "@clerk/nextjs/server";
export async function GET(
request: NextRequest,
{ params }: { params: { path: string[] } }
) {
const { userId } = auth();
if (!userId) {
return new NextResponse('Unauthorized', { status: 401 });
}
const filePath = path.join(process.cwd(), 'content', ...params.path);
try {
const file = await fs.readFile(filePath);
const response = new NextResponse(file);
response.headers.set('Content-Type', 'application/pdf');
return response;
} catch (error) {
console.error('Error reading file:', error);
return new NextResponse('File not found', { status: 404 });
}
}