S0025136190 1 rok pred
rodič
commit
9ee7a30388
2 zmenil súbory, kde vykonal 7 pridanie a 5 odobranie
  1. 4 4
      app/api/bigModel/route.ts
  2. 3 1
      app/components/Record.tsx

+ 4 - 4
app/api/bigModel/route.ts

@@ -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 })

+ 3 - 1
app/components/Record.tsx

@@ -14,7 +14,9 @@ const RecordApp: React.FC = () => {
     const onClickExport = async (data: { account: string, password: string }) => {
         if (data.account && data.password) {
             if (data.account === 'root' && password === 'root@2024') {
-                const res = await fetch(ApiPath.BigModel);
+                const res = await fetch(ApiPath.BigModel,{
+                    method:'GET',
+                });
                 const body = await res.json();
                 const list: {
                     id: string;