From 7c40fb6ac9bdf0139964ee7f7fe0d13a11560fb6 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Thu, 16 Apr 2026 12:24:57 +0800 Subject: [PATCH] feat: enhance URL validation and timeout handling in knowledge base components - Added isValidURL function to validate URLs before rendering links in the document content component, preventing invalid links from being clickable. - Refactored timeout handling in KnowledgeBase.vue to use setTimeout instead of setInterval, improving performance and resource management. - Ensured that timeouts are cleared appropriately to avoid memory leaks and unnecessary polling. This update improves the robustness of URL handling and optimizes the component's performance. --- frontend/src/components/doc-content.vue | 4 +- .../src/views/knowledge/KnowledgeBase.vue | 52 ++++++++++++++++--- internal/utils/security.go | 4 +- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/doc-content.vue b/frontend/src/components/doc-content.vue index 6f659607..f22c41d8 100644 --- a/frontend/src/components/doc-content.vue +++ b/frontend/src/components/doc-content.vue @@ -8,7 +8,7 @@ import mermaid from "mermaid"; import { onMounted, ref, nextTick, onUnmounted, watch, computed } from "vue"; import { downKnowledgeDetails, deleteGeneratedQuestion, getChunkByIdOnly, previewKnowledgeFile } from "@/api/knowledge-base/index"; import { MessagePlugin, DialogPlugin } from "tdesign-vue-next"; -import { sanitizeHTML, safeMarkdownToHTML, createSafeImage, isValidImageURL, hydrateProtectedFileImages } from '@/utils/security'; +import { sanitizeHTML, safeMarkdownToHTML, createSafeImage, isValidImageURL, hydrateProtectedFileImages, isValidURL } from '@/utils/security'; import { openMermaidFullscreen } from '@/utils/mermaidViewer'; import { useI18n } from 'vue-i18n'; import DocumentPreview from '@/components/document-preview.vue'; @@ -778,7 +778,7 @@ const handleDetailsScroll = () => {
{{ $t('knowledgeBase.urlSource') }}