Commit 72a9307e by archer

fix: chat data outsize

parent 2f81fbc4
...@@ -11,6 +11,7 @@ import SideTabs from '@/components/SideTabs'; ...@@ -11,6 +11,7 @@ import SideTabs from '@/components/SideTabs';
import Tabs from '@/components/Tabs'; import Tabs from '@/components/Tabs';
import UserInfo from './components/Info'; import UserInfo from './components/Info';
import { serviceSideProps } from '@/utils/i18n'; import { serviceSideProps } from '@/utils/i18n';
import { feConfigs } from '@/store/static';
const BillTable = dynamic(() => import('./components/BillTable'), { const BillTable = dynamic(() => import('./components/BillTable'), {
ssr: false ssr: false
......
...@@ -52,7 +52,7 @@ export const jsonRes = <T = any>( ...@@ -52,7 +52,7 @@ export const jsonRes = <T = any>(
} else if (openaiError[error?.response?.statusText]) { } else if (openaiError[error?.response?.statusText]) {
msg = openaiError[error.response.statusText]; msg = openaiError[error.response.statusText];
} }
console.log(error); console.log(error?.response);
} }
res.status(code).json({ res.status(code).json({
...@@ -92,7 +92,7 @@ export const sseErrRes = (res: NextApiResponse, error: any) => { ...@@ -92,7 +92,7 @@ export const sseErrRes = (res: NextApiResponse, error: any) => {
} else if (openaiError[error?.response?.statusText]) { } else if (openaiError[error?.response?.statusText]) {
msg = openaiError[error.response.statusText]; msg = openaiError[error.response.statusText];
} }
console.log('sse error => ', error); console.log('sse error => ', error?.response);
sseResponse({ sseResponse({
res, res,
......
...@@ -23,54 +23,68 @@ export async function saveChat({ ...@@ -23,54 +23,68 @@ export async function saveChat({
shareId, shareId,
content content
}: Props) { }: Props) {
const chatHistory = await Chat.findOne( try {
{ const chatHistory = await Chat.findOne(
chatId, {
userId chatId,
}, userId
'_id' },
); '_id'
);
const promise = []; const promise = [];
if (chatHistory) { if (chatHistory) {
promise.push( promise.push(
Chat.updateOne( Chat.updateOne(
{ chatId, userId }, { chatId, userId },
{ {
$push: { $push: {
content: { content: {
$each: content, $each: content,
$slice: -50 $slice: -40
} }
}, },
title: content[0].value.slice(0, 20),
updateTime: new Date()
}
)
);
} else {
promise.push(
Chat.create({
chatId,
userId,
appId,
variables,
title: content[0].value.slice(0, 20), title: content[0].value.slice(0, 20),
source,
shareId,
content: content
})
);
}
if (isOwner && source === ChatSourceEnum.online) {
promise.push(
App.findByIdAndUpdate(appId, {
updateTime: new Date() updateTime: new Date()
} })
) );
); }
} else {
promise.push(
Chat.create({
chatId,
userId,
appId,
variables,
title: content[0].value.slice(0, 20),
source,
shareId,
content: content
})
);
}
if (isOwner && source === ChatSourceEnum.online) { await Promise.all(promise);
promise.push( } catch (error) {
App.findByIdAndUpdate(appId, { Chat.updateOne(
updateTime: new Date() { chatId, userId },
}) {
$push: {
content: {
$each: [],
$slice: -10
}
}
}
); );
} }
await Promise.all(promise);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment