feat: 复制和删除对话功能
This commit is contained in:
@@ -4,18 +4,20 @@ import { connectToDatabase, Chat } from '@/service/mongo';
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
try {
|
||||
const { chatId } = req.query as { chatId: string };
|
||||
const { chatId, index } = req.query as { chatId: string; index: string };
|
||||
|
||||
if (!chatId) {
|
||||
if (!chatId || !index) {
|
||||
throw new Error('缺少参数');
|
||||
}
|
||||
|
||||
console.log(index);
|
||||
await connectToDatabase();
|
||||
|
||||
// 删除最一条数据库记录, 也就是预发送的那一条
|
||||
await Chat.findByIdAndUpdate(chatId, {
|
||||
$pop: { content: 1 },
|
||||
updateTime: Date.now()
|
||||
$set: {
|
||||
[`content.${index}.deleted`]: true,
|
||||
updateTime: Date.now()
|
||||
}
|
||||
});
|
||||
|
||||
jsonRes(res);
|
||||
@@ -42,7 +42,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
modelId,
|
||||
expiredTime: Date.now() + model.security.expiredTime,
|
||||
loadAmount: model.security.maxLoadAmount,
|
||||
updateTime: Date.now(),
|
||||
isShare: isShare === 'true',
|
||||
content: []
|
||||
});
|
||||
|
||||
@@ -38,6 +38,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
);
|
||||
}
|
||||
|
||||
// filter 掉被 deleted 的内容
|
||||
chat.content = chat.content.filter((item) => item.deleted !== true);
|
||||
|
||||
const model = chat.modelId;
|
||||
jsonRes<InitChatResponse>(res, {
|
||||
code: 201,
|
||||
|
||||
@@ -27,7 +27,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
}))
|
||||
}
|
||||
},
|
||||
updateTime: Date.now()
|
||||
updateTime: new Date()
|
||||
});
|
||||
|
||||
jsonRes(res);
|
||||
|
||||
Reference in New Issue
Block a user