Spaces:
Running
Running
import { dbPostCreateChat } from '@/lib/db/functions'; | |
import { MessageRaw } from '@/lib/db/types'; | |
import { withLogging } from '@/lib/logger'; | |
import { revalidatePath } from 'next/cache'; | |
/** | |
* @param req | |
* @returns | |
*/ | |
export const POST = withLogging( | |
async ( | |
_session, | |
json: { | |
id?: string; | |
url: string; | |
initMessages?: MessageRaw[]; | |
}, | |
): Promise<Response> => { | |
try { | |
const { url, id, initMessages } = json; | |
const response = await dbPostCreateChat({ | |
id, | |
mediaUrl: url, | |
initMessages, | |
}); | |
revalidatePath('/chat', 'layout'); | |
return Response.json(response); | |
} catch (error) { | |
return new Response((error as Error).message, { | |
status: 400, | |
}); | |
} | |
}, | |
); | |