mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-13 21:05:19 +00:00
refac: knowledge item modal
This commit is contained in:
parent
8e25eb104b
commit
b9885529a5
2 changed files with 61 additions and 30 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getContext, onMount } from 'svelte';
|
import { getContext, onMount, tick } from 'svelte';
|
||||||
import { formatFileSize, getLineCount } from '$lib/utils';
|
import { formatFileSize, getLineCount } from '$lib/utils';
|
||||||
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
||||||
|
import { getKnowledgeById } from '$lib/apis/knowledge';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
|
@ -11,6 +12,7 @@
|
||||||
import Switch from './Switch.svelte';
|
import Switch from './Switch.svelte';
|
||||||
import Tooltip from './Tooltip.svelte';
|
import Tooltip from './Tooltip.svelte';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
import Spinner from './Spinner.svelte';
|
||||||
|
|
||||||
export let item;
|
export let item;
|
||||||
export let show = false;
|
export let show = false;
|
||||||
|
|
@ -20,6 +22,7 @@
|
||||||
|
|
||||||
let isPdf = false;
|
let isPdf = false;
|
||||||
let isAudio = false;
|
let isAudio = false;
|
||||||
|
let loading = false;
|
||||||
|
|
||||||
$: isPDF =
|
$: isPDF =
|
||||||
item?.meta?.content_type === 'application/pdf' ||
|
item?.meta?.content_type === 'application/pdf' ||
|
||||||
|
|
@ -33,6 +36,28 @@
|
||||||
(item?.name && item?.name.toLowerCase().endsWith('.m4a')) ||
|
(item?.name && item?.name.toLowerCase().endsWith('.m4a')) ||
|
||||||
(item?.name && item?.name.toLowerCase().endsWith('.webm'));
|
(item?.name && item?.name.toLowerCase().endsWith('.webm'));
|
||||||
|
|
||||||
|
const loadContent = async () => {
|
||||||
|
if (item?.type === 'collection') {
|
||||||
|
loading = true;
|
||||||
|
|
||||||
|
const knowledge = await getKnowledgeById(localStorage.token, item.id).catch((e) => {
|
||||||
|
console.error('Error fetching knowledge base:', e);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (knowledge) {
|
||||||
|
item.files = knowledge.files || [];
|
||||||
|
}
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await tick();
|
||||||
|
};
|
||||||
|
|
||||||
|
$: if (show) {
|
||||||
|
loadContent();
|
||||||
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
console.log(item);
|
console.log(item);
|
||||||
if (item?.context === 'full') {
|
if (item?.context === 'full') {
|
||||||
|
|
@ -152,6 +177,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="max-h-[75vh] overflow-auto">
|
<div class="max-h-[75vh] overflow-auto">
|
||||||
|
{#if !loading}
|
||||||
{#if item?.type === 'collection'}
|
{#if item?.type === 'collection'}
|
||||||
<div>
|
<div>
|
||||||
{#each item?.files as file}
|
{#each item?.files as file}
|
||||||
|
|
@ -184,6 +210,11 @@
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<div class="flex items-center justify-center py-6">
|
||||||
|
<Spinner className="size-5" />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
|
||||||
|
|
@ -181,7 +181,7 @@
|
||||||
loading={file.status === 'uploading'}
|
loading={file.status === 'uploading'}
|
||||||
type={file?.legacy
|
type={file?.legacy
|
||||||
? `Legacy${file.type ? ` ${file.type}` : ''}`
|
? `Legacy${file.type ? ` ${file.type}` : ''}`
|
||||||
: (file?.type ?? 'Collection')}
|
: (file?.type ?? 'collection')}
|
||||||
dismissible
|
dismissible
|
||||||
on:dismiss={(e) => {
|
on:dismiss={(e) => {
|
||||||
selectedItems = selectedItems.filter((_, idx) => idx !== fileIdx);
|
selectedItems = selectedItems.filter((_, idx) => idx !== fileIdx);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue