feat: export kb to zip

This commit is contained in:
Timothy Jaeryang Baek
2026-01-08 12:49:45 +04:00
parent 9b06fdc8fe
commit c1147578c0
5 changed files with 139 additions and 2 deletions
+29 -1
View File
@@ -8,7 +8,11 @@
const i18n = getContext('i18n');
import { WEBUI_NAME, knowledge, user } from '$lib/stores';
import { deleteKnowledgeById, searchKnowledgeBases } from '$lib/apis/knowledge';
import {
deleteKnowledgeById,
searchKnowledgeBases,
exportKnowledgeById
} from '$lib/apis/knowledge';
import { goto } from '$app/navigation';
import { capitalizeFirstLetter } from '$lib/utils';
@@ -104,6 +108,25 @@
}
};
const exportHandler = async (item) => {
try {
const blob = await exportKnowledgeById(localStorage.token, item.id);
if (blob) {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${item.name}.zip`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
toast.success($i18n.t('Knowledge exported successfully'));
}
} catch (e) {
toast.error(`${e}`);
}
};
onMount(async () => {
viewOption = localStorage?.workspaceViewOption || '';
loaded = true;
@@ -239,6 +262,11 @@
<div class="flex items-center gap-2">
<div class=" flex self-center">
<ItemMenu
onExport={$user.role === 'admin'
? () => {
exportHandler(item);
}
: null}
on:delete={() => {
selectedItem = item;
showDeleteConfirm = true;
@@ -18,6 +18,7 @@
const i18n = getContext('i18n');
export let onExport: null | Function = null;
export let onClose: Function = () => {};
let show = false;
@@ -54,6 +55,18 @@
align="end"
transition={flyAndScale}
>
{#if onExport}
<DropdownMenu.Item
class="flex gap-2 items-center px-3 py-1.5 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-xl"
on:click={() => {
onExport();
}}
>
<Download />
<div class="flex items-center">{$i18n.t('Export')}</div>
</DropdownMenu.Item>
{/if}
<DropdownMenu.Item
class="flex gap-2 items-center px-3 py-1.5 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-xl"
on:click={() => {