mirror of
https://github.com/open-webui/open-webui
synced 2025-05-19 04:43:00 +00:00
feat: archive all
This commit is contained in:
parent
bf8c32f09f
commit
83107c8ea5
@ -148,7 +148,7 @@ async def get_archived_session_user_chat_list(
|
|||||||
############################
|
############################
|
||||||
|
|
||||||
|
|
||||||
@router.get("/archive/all", response_model=List[ChatTitleIdResponse])
|
@router.post("/archive/all", response_model=List[ChatTitleIdResponse])
|
||||||
async def archive_all_chats(user=Depends(get_current_user)):
|
async def archive_all_chats(user=Depends(get_current_user)):
|
||||||
return Chats.archive_all_chats_by_user_id(user.id)
|
return Chats.archive_all_chats_by_user_id(user.id)
|
||||||
|
|
||||||
|
@ -654,3 +654,35 @@ export const deleteAllChats = async (token: string) => {
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const archiveAllChats = async (token: string) => {
|
||||||
|
let error = null;
|
||||||
|
|
||||||
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/archive/all`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...(token && { authorization: `Bearer ${token}` })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw await res.json();
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then((json) => {
|
||||||
|
return json;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
error = err.detail;
|
||||||
|
|
||||||
|
console.log(err);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
import { chats, user, config } from '$lib/stores';
|
import { chats, user, config } from '$lib/stores';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
archiveAllChats,
|
||||||
createNewChat,
|
createNewChat,
|
||||||
deleteAllChats,
|
deleteAllChats,
|
||||||
getAllChats,
|
getAllChats,
|
||||||
@ -22,7 +23,10 @@
|
|||||||
// Chats
|
// Chats
|
||||||
let saveChatHistory = true;
|
let saveChatHistory = true;
|
||||||
let importFiles;
|
let importFiles;
|
||||||
|
|
||||||
|
let showArchiveConfirm = false;
|
||||||
let showDeleteConfirm = false;
|
let showDeleteConfirm = false;
|
||||||
|
|
||||||
let chatImportInputElement: HTMLInputElement;
|
let chatImportInputElement: HTMLInputElement;
|
||||||
|
|
||||||
$: if (importFiles) {
|
$: if (importFiles) {
|
||||||
@ -68,6 +72,14 @@
|
|||||||
saveAs(blob, `chat-export-${Date.now()}.json`);
|
saveAs(blob, `chat-export-${Date.now()}.json`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const archiveAllChatsHandler = async () => {
|
||||||
|
await goto('/');
|
||||||
|
await archiveAllChats(localStorage.token).catch((error) => {
|
||||||
|
toast.error(error);
|
||||||
|
});
|
||||||
|
await chats.set(await getChatList(localStorage.token));
|
||||||
|
};
|
||||||
|
|
||||||
const deleteAllChatsHandler = async () => {
|
const deleteAllChatsHandler = async () => {
|
||||||
await goto('/');
|
await goto('/');
|
||||||
await deleteAllChats(localStorage.token).catch((error) => {
|
await deleteAllChats(localStorage.token).catch((error) => {
|
||||||
@ -210,6 +222,94 @@
|
|||||||
|
|
||||||
<hr class=" dark:border-gray-700" />
|
<hr class=" dark:border-gray-700" />
|
||||||
|
|
||||||
|
<div class="flex flex-col">
|
||||||
|
{#if showArchiveConfirm}
|
||||||
|
<div class="flex justify-between rounded-md items-center py-2 px-3.5 w-full transition">
|
||||||
|
<div class="flex items-center space-x-3">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
fill="currentColor"
|
||||||
|
class="w-4 h-4"
|
||||||
|
>
|
||||||
|
<path d="M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3Z" />
|
||||||
|
<path
|
||||||
|
fill-rule="evenodd"
|
||||||
|
d="M13 6H3v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V6ZM5.72 7.47a.75.75 0 0 1 1.06 0L8 8.69l1.22-1.22a.75.75 0 1 1 1.06 1.06L9.06 9.75l1.22 1.22a.75.75 0 1 1-1.06 1.06L8 10.81l-1.22 1.22a.75.75 0 0 1-1.06-1.06l1.22-1.22-1.22-1.22a.75.75 0 0 1 0-1.06Z"
|
||||||
|
clip-rule="evenodd"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
<span>{$i18n.t('Are you sure?')}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex space-x-1.5 items-center">
|
||||||
|
<button
|
||||||
|
class="hover:text-white transition"
|
||||||
|
on:click={() => {
|
||||||
|
archiveAllChatsHandler();
|
||||||
|
showArchiveConfirm = false;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox="0 0 20 20"
|
||||||
|
fill="currentColor"
|
||||||
|
class="w-4 h-4"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
fill-rule="evenodd"
|
||||||
|
d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
|
||||||
|
clip-rule="evenodd"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="hover:text-white transition"
|
||||||
|
on:click={() => {
|
||||||
|
showArchiveConfirm = false;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox="0 0 20 20"
|
||||||
|
fill="currentColor"
|
||||||
|
class="w-4 h-4"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<button
|
||||||
|
class=" flex rounded-md py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
|
||||||
|
on:click={() => {
|
||||||
|
showArchiveConfirm = true;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div class=" self-center mr-3">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="currentColor"
|
||||||
|
class="size-4"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M3.375 3C2.339 3 1.5 3.84 1.5 4.875v.75c0 1.036.84 1.875 1.875 1.875h17.25c1.035 0 1.875-.84 1.875-1.875v-.75C22.5 3.839 21.66 3 20.625 3H3.375Z"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
fill-rule="evenodd"
|
||||||
|
d="m3.087 9 .54 9.176A3 3 0 0 0 6.62 21h10.757a3 3 0 0 0 2.995-2.824L20.913 9H3.087Zm6.163 3.75A.75.75 0 0 1 10 12h4a.75.75 0 0 1 0 1.5h-4a.75.75 0 0 1-.75-.75Z"
|
||||||
|
clip-rule="evenodd"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class=" self-center text-sm font-medium">{$i18n.t('Archive All Chats')}</div>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if showDeleteConfirm}
|
{#if showDeleteConfirm}
|
||||||
<div class="flex justify-between rounded-md items-center py-2 px-3.5 w-full transition">
|
<div class="flex justify-between rounded-md items-center py-2 px-3.5 w-full transition">
|
||||||
<div class="flex items-center space-x-3">
|
<div class="flex items-center space-x-3">
|
||||||
@ -295,3 +395,4 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
@ -101,6 +101,7 @@
|
|||||||
<hr class=" dark:border-gray-850 my-2" />
|
<hr class=" dark:border-gray-850 my-2" />
|
||||||
<div class=" flex flex-col w-full sm:flex-row sm:justify-center sm:space-x-6">
|
<div class=" flex flex-col w-full sm:flex-row sm:justify-center sm:space-x-6">
|
||||||
{#if chats.length > 0}
|
{#if chats.length > 0}
|
||||||
|
<div>
|
||||||
<div class="text-left text-sm w-full mb-3 max-h-[22rem] overflow-y-scroll">
|
<div class="text-left text-sm w-full mb-3 max-h-[22rem] overflow-y-scroll">
|
||||||
<div class="relative overflow-x-auto">
|
<div class="relative overflow-x-auto">
|
||||||
<table class="w-full text-sm text-left text-gray-600 dark:text-gray-400 table-auto">
|
<table class="w-full text-sm text-left text-gray-600 dark:text-gray-400 table-auto">
|
||||||
@ -109,7 +110,9 @@
|
|||||||
>
|
>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" class="px-3 py-2"> {$i18n.t('Name')} </th>
|
<th scope="col" class="px-3 py-2"> {$i18n.t('Name')} </th>
|
||||||
<th scope="col" class="px-3 py-2 hidden md:flex"> {$i18n.t('Created At')} </th>
|
<th scope="col" class="px-3 py-2 hidden md:flex">
|
||||||
|
{$i18n.t('Created At')}
|
||||||
|
</th>
|
||||||
<th scope="col" class="px-3 py-2 text-right" />
|
<th scope="col" class="px-3 py-2 text-right" />
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -191,6 +194,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-wrap text-sm font-medium gap-1.5 mt-2 m-1">
|
<div class="flex flex-wrap text-sm font-medium gap-1.5 mt-2 m-1">
|
||||||
<button
|
<button
|
||||||
|
Loading…
Reference in New Issue
Block a user