|
1 | | -import { type NextRequest, NextResponse } from "next/server"; |
2 | | -import { db } from "@/lib/prisma"; |
3 | | - |
4 | | -export async function POST(req: NextRequest) { |
5 | | - const body = await req.json(); |
6 | | - const { agentId, name, size, type, url } = body; |
7 | | - |
8 | | - if (!agentId || !name || !size || !type || !url) { |
9 | | - return NextResponse.json( |
10 | | - { error: "Missing required fields" }, |
11 | | - { status: 400 } |
12 | | - ); |
13 | | - } |
14 | | - |
15 | | - try { |
16 | | - await db.docs.create({ |
17 | | - data: { agentId, name, size, type, url }, |
18 | | - }); |
19 | | - return NextResponse.json({ success: true }); |
20 | | - } catch (error) { |
21 | | - console.error("Error saving file:", error); |
22 | | - return NextResponse.json({ error: "Failed to save file" }, { status: 500 }); |
23 | | - } |
24 | | -} |
| 1 | +import { type NextRequest, NextResponse } from 'next/server' |
| 2 | +import { db } from '@/lib/prisma' |
| 3 | + |
| 4 | +export async function POST(req: NextRequest): Promise<NextResponse> { |
| 5 | + const body = await req.json() |
| 6 | + const { agentId, name, size, type, url } = body |
| 7 | + |
| 8 | + if (!agentId || !name || !size || !type || !url) { |
| 9 | + return NextResponse.json( |
| 10 | + { error: 'Missing required fields' }, |
| 11 | + { status: 400 }, |
| 12 | + ) |
| 13 | + } |
| 14 | + |
| 15 | + try { |
| 16 | + const file = await db.docs.create({ |
| 17 | + data: { agentId, name, size, type, url }, |
| 18 | + }) |
| 19 | + return NextResponse.json(file, { status: 201 }) |
| 20 | + } catch (error) { |
| 21 | + console.error('Error saving file:', error) |
| 22 | + return NextResponse.json({ error: 'Failed to save file' }, { status: 500 }) |
| 23 | + } |
| 24 | +} |
0 commit comments