Skip to content

Commit ee0d9b7

Browse files
authored
feat: knowledge - clickable file icon opens content (open-webui#22629)
Replaces the static document icon with an interactive button that opens the file content in a new tab via the files API endpoint.
1 parent f3402d3 commit ee0d9b7

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

  • src/lib/components/workspace/Knowledge/KnowledgeBase

src/lib/components/workspace/Knowledge/KnowledgeBase/Files.svelte

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
1212
import { capitalizeFirstLetter, formatFileSize } from '$lib/utils';
1313
14+
import { WEBUI_BASE_URL } from '$lib/constants';
15+
1416
import Tooltip from '$lib/components/common/Tooltip.svelte';
1517
import DocumentPage from '$lib/components/icons/DocumentPage.svelte';
1618
import XMark from '$lib/components/icons/XMark.svelte';
@@ -31,6 +33,25 @@
3133
? ''
3234
: 'hover:bg-gray-100 dark:hover:bg-gray-850'}"
3335
>
36+
<div class="flex items-center">
37+
{#if file?.status !== 'uploading'}
38+
<Tooltip content={$i18n.t('Open file')}>
39+
<button
40+
class="p-1 rounded-full hover:bg-gray-100 dark:hover:bg-gray-850 transition"
41+
type="button"
42+
on:click={() => {
43+
let fileId = file?.id ?? file?.tempId;
44+
window.open(`${WEBUI_BASE_URL}/api/v1/files/${fileId}/content`, '_blank');
45+
}}
46+
>
47+
<DocumentPage className="size-3.5" />
48+
</button>
49+
</Tooltip>
50+
{:else}
51+
<Spinner className="size-3.5" />
52+
{/if}
53+
</div>
54+
3455
<button
3556
class="relative group flex items-center gap-1 rounded-xl p-2 text-left flex-1 justify-between"
3657
type="button"
@@ -41,14 +62,6 @@
4162
>
4263
<div class="">
4364
<div class="flex gap-2 items-center line-clamp-1">
44-
<div class="shrink-0">
45-
{#if file?.status !== 'uploading'}
46-
<DocumentPage className="size-3.5" />
47-
{:else}
48-
<Spinner className="size-3.5" />
49-
{/if}
50-
</div>
51-
5265
<div class="line-clamp-1 text-sm">
5366
{file?.name ?? file?.meta?.name}
5467
{#if file?.meta?.size}

0 commit comments

Comments
 (0)