mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 15:58:38 +01:00
add delete chat
This commit is contained in:
@@ -105,6 +105,18 @@ const defaultPrompts = [
|
|||||||
'How many events i got last week ?',
|
'How many events i got last week ?',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
async function deleteChat(chat_id: string) {
|
||||||
|
if (!activeProject.value) return;
|
||||||
|
const sure = confirm("Are you sure to delete the chat ?");
|
||||||
|
if (!sure) return;
|
||||||
|
if (currentChatId.value === chat_id) {
|
||||||
|
currentChatId.value = "";
|
||||||
|
currentChatMessages.value = [];
|
||||||
|
}
|
||||||
|
await $fetch(`/api/ai/${activeProject.value._id}/${chat_id}/delete`, signHeaders());
|
||||||
|
await reloadChatsList();
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -213,11 +225,16 @@ const defaultPrompts = [
|
|||||||
|
|
||||||
<div class="overflow-y-auto">
|
<div class="overflow-y-auto">
|
||||||
<div class="flex flex-col gap-2 px-2">
|
<div class="flex flex-col gap-2 px-2">
|
||||||
<div @click="openChat(chat._id.toString())" v-for="chat of chatsList?.toReversed()"
|
<div class="flex items-center gap-4 w-full" v-for="chat of chatsList?.toReversed()">
|
||||||
class="bg-menu px-4 py-3 cursor-pointer hover:bg-menu/80 poppins rounded-lg"
|
<i @click="deleteChat(chat._id.toString())"
|
||||||
:class="{ '!bg-accent/60': chat._id.toString() === currentChatId }">
|
class="fas fa-trash hover:text-gray-300 cursor-pointer"></i>
|
||||||
{{ chat.title }}
|
<div @click="openChat(chat._id.toString())"
|
||||||
|
class="bg-menu px-4 py-3 w-full cursor-pointer hover:bg-menu/80 poppins rounded-lg"
|
||||||
|
:class="{ '!bg-accent/60': chat._id.toString() === currentChatId }">
|
||||||
|
{{ chat.title }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
21
dashboard/server/api/ai/[project_id]/[chat_id]/delete.ts
Normal file
21
dashboard/server/api/ai/[project_id]/[chat_id]/delete.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
||||||
|
import { AiChatModel } from "@schema/ai/AiChatSchema";
|
||||||
|
import { sendMessageOnChat } from "~/server/services/AiService";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export default defineEventHandler(async event => {
|
||||||
|
|
||||||
|
const project_id = getRequestProjectId(event);
|
||||||
|
if (!project_id) return;
|
||||||
|
|
||||||
|
const user = getRequestUser(event);
|
||||||
|
const project = await getUserProjectFromId(project_id, user);
|
||||||
|
if (!project) return;
|
||||||
|
|
||||||
|
if (!event.context.params) return;
|
||||||
|
const chat_id = event.context.params['chat_id'];
|
||||||
|
|
||||||
|
const result = await AiChatModel.deleteOne({ _id: chat_id, project_id });
|
||||||
|
return result.deletedCount > 0;
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user