refac: only open web, mail, phone and relative file links (#31491)

File attachment links and the file links in code execution results now go through the same link check as links in chat messages, so only web, mail, phone and relative links are opened.
This commit is contained in:
Classic298 2026-09-27 23:52:15 +02:00 • committed by GitHub
parent fc9ad75164
commit b6f9679985
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 5 deletions

View file

@ -1,5 +1,6 @@
<script lang="ts">
import { getContext } from 'svelte';
import { safeLinkUrl } from '$lib/utils';
import CodeBlock from './CodeBlock.svelte';
import Modal from '$lib/components/common/Modal.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
@ -97,7 +98,7 @@
<ul class="mt-1 list-disc pl-4 text-xs">
{#each codeExecution?.result?.files as file}
<li>
<a href={file.url} target="_blank">{file.name}</a>
<a href={safeLinkUrl(file.url)} target="_blank">{file.name}</a>
</li>
{/each}
</ul>

View file

@ -2,7 +2,7 @@
import { createEventDispatcher, getContext } from 'svelte';
import { WEBUI_API_BASE_URL } from '$lib/constants';
import { formatFileSize } from '$lib/utils';
import { formatFileSize, safeLinkUrl } from '$lib/utils';
import { settings, showFileNavPath } from '$lib/stores';
import FileItemModal from './FileItemModal.svelte';
@ -71,7 +71,7 @@
} else {
window.open(`${WEBUI_API_BASE_URL}/files/${url}/content`, '_blank').focus();
}
} else {
} else if (safeLinkUrl(url)) {
window.open(`${url}`, '_blank').focus();
}
}

View file

@ -4,7 +4,7 @@
import { getContext, onMount, tick } from 'svelte';
import { formatFileSize, getLineCount } from '$lib/utils';
import { formatFileSize, getLineCount, safeLinkUrl } from '$lib/utils';
import { WEBUI_API_BASE_URL } from '$lib/constants';
import { settings } from '$lib/stores';
import { getKnowledgeById } from '$lib/apis/knowledge';
@ -264,7 +264,7 @@
href="#"
class="hover:underline line-clamp-1"
on:click|preventDefault={() => {
if (item.type === 'file' || item.url) {
if (item.type === 'file' || safeLinkUrl(item.url)) {
let fileId = item?.id ?? item?.tempId;
window.open(
item.type === 'file'