mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-30 10:28:42 +00:00
fix: save chat and hook
This commit is contained in:
@@ -19,7 +19,7 @@ export const pushTaskBill = async ({
|
||||
shareId?: string;
|
||||
response: ChatHistoryItemResType[];
|
||||
}) => {
|
||||
const total = response.reduce((sum, item) => sum + item.price, 0) || 1;
|
||||
const total = response.reduce((sum, item) => sum + item.price, 0);
|
||||
|
||||
await Promise.allSettled([
|
||||
Bill.create({
|
||||
|
@@ -179,10 +179,10 @@ export const authApp = async ({
|
||||
authOwner?: boolean;
|
||||
reserveDetail?: boolean; // focus reserve detail
|
||||
}) => {
|
||||
// 获取 model 数据
|
||||
// 获取 app 数据
|
||||
const app = await App.findById<AppSchema>(appId);
|
||||
if (!app) {
|
||||
return Promise.reject('模型不存在');
|
||||
return Promise.reject('App is not exists');
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -31,35 +31,45 @@ export async function saveChat({
|
||||
'_id'
|
||||
);
|
||||
|
||||
const promise = [];
|
||||
|
||||
if (chatHistory) {
|
||||
await Chat.findOneAndUpdate(
|
||||
{ chatId },
|
||||
{
|
||||
$push: {
|
||||
content: {
|
||||
$each: content
|
||||
}
|
||||
},
|
||||
title: content[0].value.slice(0, 20),
|
||||
updateTime: new Date()
|
||||
}
|
||||
promise.push(
|
||||
Chat.findOneAndUpdate(
|
||||
{ chatId },
|
||||
{
|
||||
$push: {
|
||||
content: {
|
||||
$each: content
|
||||
}
|
||||
},
|
||||
title: content[0].value.slice(0, 20),
|
||||
updateTime: new Date()
|
||||
}
|
||||
)
|
||||
);
|
||||
} else {
|
||||
await Chat.create({
|
||||
chatId,
|
||||
userId,
|
||||
appId,
|
||||
variables,
|
||||
title: content[0].value.slice(0, 20),
|
||||
source,
|
||||
shareId,
|
||||
content: content
|
||||
});
|
||||
promise.push(
|
||||
Chat.create({
|
||||
chatId,
|
||||
userId,
|
||||
appId,
|
||||
variables,
|
||||
title: content[0].value.slice(0, 20),
|
||||
source,
|
||||
shareId,
|
||||
content: content
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (isOwner && source === ChatSourceEnum.online) {
|
||||
App.findByIdAndUpdate(appId, {
|
||||
updateTime: new Date()
|
||||
});
|
||||
promise.push(
|
||||
App.findByIdAndUpdate(appId, {
|
||||
updateTime: new Date()
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
await Promise.all(promise);
|
||||
}
|
||||
|
Reference in New Issue
Block a user