diff --git a/client/src/pages/api/admin/initv4.ts b/client/src/pages/api/admin/initv4.ts index ef7d67096..213a00d6c 100644 --- a/client/src/pages/api/admin/initv4.ts +++ b/client/src/pages/api/admin/initv4.ts @@ -385,8 +385,8 @@ async function init(limit: number, skip: number) { // 遍历 app const apps = await App.find( { - chat: { $ne: null } - // modules: { $exists: false }, + chat: { $ne: null }, + modules: { $exists: false } // userId: '63f9a14228d2a688d8dc9e1b' }, '_id chat' diff --git a/client/src/pages/chat/components/ToolMenu.tsx b/client/src/pages/chat/components/ToolMenu.tsx index f241cd5cb..706b5cdd7 100644 --- a/client/src/pages/chat/components/ToolMenu.tsx +++ b/client/src/pages/chat/components/ToolMenu.tsx @@ -1,4 +1,4 @@ -import React, { useRef } from 'react'; +import React, { useMemo } from 'react'; import { useChatBox } from '@/components/ChatBox'; import { ChatItemType } from '@/types/chat'; import { Menu, MenuButton, MenuList, MenuItem, Box } from '@chakra-ui/react'; @@ -8,30 +8,36 @@ import { useRouter } from 'next/router'; const ToolMenu = ({ history }: { history: ChatItemType[] }) => { const { onExportChat } = useChatBox(); const router = useRouter(); - const menuList = useRef([ - { - icon: 'chat', - label: '新对话', - onClick: () => { - router.push({ - query: { - appId: router.query?.appId - } - }); - } - }, - { - icon: 'apiLight', - label: 'HTML导出', - onClick: () => onExportChat({ type: 'html', history }) - }, - { - icon: 'markdown', - label: 'Markdown导出', - onClick: () => onExportChat({ type: 'md', history }) - }, - { icon: 'pdf', label: 'PDF导出', onClick: () => onExportChat({ type: 'pdf', history }) } - ]); + const { appId } = router.query; + + const menuList = useMemo( + () => [ + { + icon: 'chat', + label: '新对话', + onClick: () => { + router.push({ + query: { + appId + } + }); + } + }, + { + icon: 'apiLight', + label: 'HTML导出', + onClick: () => onExportChat({ type: 'html', history }) + }, + { + icon: 'markdown', + label: 'Markdown导出', + onClick: () => onExportChat({ type: 'md', history }) + }, + { icon: 'pdf', label: 'PDF导出', onClick: () => onExportChat({ type: 'pdf', history }) } + ], + [appId, history, onExportChat, router] + ); + return history.length > 0 ? ( { - {menuList.current.map((item) => ( + {menuList.map((item) => ( {item.label} diff --git a/client/src/service/events/pushBill.ts b/client/src/service/events/pushBill.ts index d3f3b376d..709298ccb 100644 --- a/client/src/service/events/pushBill.ts +++ b/client/src/service/events/pushBill.ts @@ -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({ diff --git a/client/src/service/utils/auth.ts b/client/src/service/utils/auth.ts index 751f12b79..45fbcfacf 100644 --- a/client/src/service/utils/auth.ts +++ b/client/src/service/utils/auth.ts @@ -179,10 +179,10 @@ export const authApp = async ({ authOwner?: boolean; reserveDetail?: boolean; // focus reserve detail }) => { - // 获取 model 数据 + // 获取 app 数据 const app = await App.findById(appId); if (!app) { - return Promise.reject('模型不存在'); + return Promise.reject('App is not exists'); } /* diff --git a/client/src/service/utils/chat/saveChat.ts b/client/src/service/utils/chat/saveChat.ts index 974cfeeb3..7e7b1fd15 100644 --- a/client/src/service/utils/chat/saveChat.ts +++ b/client/src/service/utils/chat/saveChat.ts @@ -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); }