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;