MingruiZhang's picture
feat: Setup postgres and prisma (#50)
5ec491a unverified
raw
history blame
774 Bytes
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,
});
}
},
);