|
|
@@ -33,7 +33,7 @@ export async function POST(req: any) {
|
|
|
|
|
|
if ((rows as any).length === 0) {
|
|
|
// 执行 MySQL 添加头表
|
|
|
- connection.execute('INSERT INTO dialog (id, create_time) VALUES (?,?)', [id, new Date])
|
|
|
+ await connection.execute('INSERT INTO dialog (id, create_time) VALUES (?,?)', [id, new Date])
|
|
|
}
|
|
|
|
|
|
messages.forEach(async function (message) {
|
|
|
@@ -43,14 +43,14 @@ export async function POST(req: any) {
|
|
|
const content = message.content;
|
|
|
const [detailRows, fields] = await connection.query('SELECT * FROM dialog_detail where id = ?', [detailId]);
|
|
|
if ((detailRows as any).length === 0) {
|
|
|
- // 执行 MySQL 添加头表
|
|
|
- connection.execute('INSERT INTO dialog_detail (id,dialog_id,type,content,create_by, create_time) VALUES (?, ?, ?,?,?,?)', [detailId, id, role, content, role, createDate])
|
|
|
+ // 执行 MySQL 添加明细表
|
|
|
+ await connection.execute('INSERT INTO dialog_detail (id,dialog_id,type,content,create_by, create_time) VALUES (?, ?, ?,?,?,?)', [detailId, id, role, content, role, createDate])
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 释放连接回连接池
|
|
|
connection.release()
|
|
|
- return NextResponse.json({ message: 'ok', data: rows }, { status: 200 })
|
|
|
+ return NextResponse.json({ message: 'ok', data: (rows as any).length }, { status: 200 })
|
|
|
} catch (error) {
|
|
|
console.error('Error:', error)
|
|
|
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 })
|