fix: chat data outsize

This commit is contained in:
archer
2023-08-16 16:14:37 +08:00
parent 2f81fbc42f
commit 72a9307eb3
3 changed files with 64 additions and 49 deletions

View File

@@ -11,6 +11,7 @@ import SideTabs from '@/components/SideTabs';
import Tabs from '@/components/Tabs';
import UserInfo from './components/Info';
import { serviceSideProps } from '@/utils/i18n';
import { feConfigs } from '@/store/static';
const BillTable = dynamic(() => import('./components/BillTable'), {
ssr: false

View File

@@ -52,7 +52,7 @@ export const jsonRes = <T = any>(
} else if (openaiError[error?.response?.statusText]) {
msg = openaiError[error.response.statusText];
}
console.log(error);
console.log(error?.response);
}
res.status(code).json({
@@ -92,7 +92,7 @@ export const sseErrRes = (res: NextApiResponse, error: any) => {
} else if (openaiError[error?.response?.statusText]) {
msg = openaiError[error.response.statusText];
}
console.log('sse error => ', error);
console.log('sse error => ', error?.response);
sseResponse({
res,

View File

@@ -23,54 +23,68 @@ export async function saveChat({
shareId,
content
}: Props) {
const chatHistory = await Chat.findOne(
{
chatId,
userId
},
'_id'
);
const promise = [];
if (chatHistory) {
promise.push(
Chat.updateOne(
{ chatId, userId },
{
$push: {
content: {
$each: content,
$slice: -50
}
},
title: content[0].value.slice(0, 20),
updateTime: new Date()
}
)
);
} else {
promise.push(
Chat.create({
try {
const chatHistory = await Chat.findOne(
{
chatId,
userId,
appId,
variables,
title: content[0].value.slice(0, 20),
source,
shareId,
content: content
})
userId
},
'_id'
);
const promise = [];
if (chatHistory) {
promise.push(
Chat.updateOne(
{ chatId, userId },
{
$push: {
content: {
$each: content,
$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),
source,
shareId,
content: content
})
);
}
if (isOwner && source === ChatSourceEnum.online) {
promise.push(
App.findByIdAndUpdate(appId, {
updateTime: new Date()
})
);
}
await Promise.all(promise);
} catch (error) {
Chat.updateOne(
{ chatId, userId },
{
$push: {
content: {
$each: [],
$slice: -10
}
}
}
);
}
if (isOwner && source === ChatSourceEnum.online) {
promise.push(
App.findByIdAndUpdate(appId, {
updateTime: new Date()
})
);
}
await Promise.all(promise);
}