feat:自定义历史聊天标题 (#41)
* feat:自定义历史聊天标题 * Update chat.ts * perf:自定义聊天标题 * feat: google auth * perf:将修改标题移入右键菜单 * perf:updatetitle --------- Co-authored-by: archer <545436317@qq.com>
This commit is contained in:
@@ -78,13 +78,14 @@ export async function saveChat({
|
||||
return _id;
|
||||
} else {
|
||||
// 已经有记录,追加入库
|
||||
const chat = await Chat.findById(chatId);
|
||||
await Chat.findByIdAndUpdate(chatId, {
|
||||
$push: {
|
||||
content: {
|
||||
$each: content
|
||||
}
|
||||
},
|
||||
title: content[0].value.slice(0, 20),
|
||||
...(chat && !chat.customTitle ? { title: content[0].value.slice(0, 20) } : {}),
|
||||
latestChat: content[1].value,
|
||||
updateTime: new Date()
|
||||
});
|
||||
|
||||
36
src/pages/api/chat/updateChatHistoryTitle.ts
Normal file
36
src/pages/api/chat/updateChatHistoryTitle.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { jsonRes } from '@/service/response';
|
||||
import { connectToDatabase, Chat } from '@/service/mongo';
|
||||
import { authModel } from '@/service/utils/auth';
|
||||
import { authUser } from '@/service/utils/auth';
|
||||
|
||||
/* 更新聊天标题 */
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
try {
|
||||
const { chatId, modelId, newTitle } = req.body as {
|
||||
chatId: '' | string;
|
||||
modelId: '' | string;
|
||||
newTitle: string;
|
||||
};
|
||||
|
||||
const { userId } = await authUser({ req, authToken: true });
|
||||
|
||||
await connectToDatabase();
|
||||
|
||||
await authModel({ modelId, userId, authOwner: false });
|
||||
|
||||
await Chat.findByIdAndUpdate(
|
||||
chatId,
|
||||
{
|
||||
title: newTitle,
|
||||
customTitle: true
|
||||
} // 自定义标题}
|
||||
);
|
||||
jsonRes(res);
|
||||
} catch (err) {
|
||||
jsonRes(res, {
|
||||
code: 500,
|
||||
error: err
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user