Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
feat: enhance URL validation and timeout handling in knowledge base components
wizardchen7c40fb6ac9bd
diff --git a/frontend/src/components/doc-content.vue b/frontend/src/components/doc-content.vueindex 6f6596073..f22c41d8d 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 = () => {<div v-else-if="details.type === 'url'" class="url_box"><span class="label">{{ $t('knowledgeBase.urlSource') }}</span><div class="url_link_box">- <a :href="details.source" target="_blank" class="url_link">+ <a :href="isValidURL(details.source) ? details.source : 'javascript:void(0)'" :target="isValidURL(details.source) ? '_blank' : undefined" class="url_link"><t-icon name="link" size="14px" /><span class="url_text">{{ details.source }}</span><t-icon name="jump" size="14px" class="jump-icon" />diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vueindex 5e347eba2..96b74206c 100644--- a/frontend/src/views/knowledge/KnowledgeBase.vue+++ b/frontend/src/views/knowledge/KnowledgeBase.vue@@ -166,7 +166,7 @@ const onVisibleChange = (visible: boolean) => {}};let isCardDetails = ref(false);-let timeout: ReturnType<typeof setInterval> | null = null;+let timeout: ReturnType<typeof setTimeout> | null = null;let delDialog = ref(false)let rebuildDialog = ref(false)let rebuildKnowledgeItem = ref<KnowledgeCard>({ id: '', parse_status: '' })@@ -715,6 +715,10 @@ onUnmounted(() => {window.removeEventListener('knowledgeFileUploaded', handleFileUploaded as EventListener);window.removeEventListener('openURLImportDialog', handleOpenURLImportDialog as EventListener);stopMovePoll();+ if (timeout !== null) {+ clearTimeout(timeout);+ timeout = null;+ }});watch(() => cardList.value, (newValue) => {if (isFAQ.value) return;@@ -734,7 +738,7 @@ watch(() => cardList.value, (newValue) => {return isParsing || isSummaryPending;})if (timeout !== null) {- clearInterval(timeout);+ clearTimeout(timeout);timeout = null;}if (analyzeList.length) {@@ -761,25 +765,59 @@ type KnowledgeCard = {tag_id?: string;};const updateStatus = (analyzeList: KnowledgeCard[]) => {+ if (timeout !== null) {+ clearTimeout(timeout);+ timeout = null;+ }+ if (!analyzeList.length) return;+let query = ``;for (let i = 0; i < analyzeList.length; i++) {query += `ids=${analyzeList[i].id}&`;}- timeout = setInterval(() => {+ timeout = setTimeout(() => {batchQueryKnowledge(query).then((result: any) => {+ let hasChanges = false;if (result.success && result.data) {(result.data as KnowledgeCard[]).forEach((item: KnowledgeCard) => {const index = cardList.value.findIndex(card => card.id == item.id);if (index == -1) return;- // Always update the card data- cardList.value[index].parse_status = item.parse_status;- cardList.value[index].summary_status = item.summary_status;- cardList.value[index].description = item.description;+ if (cardList.value[index].parse_status !== item.parse_status ||+ cardList.value[index].summary_status !== item.summary_status ||+ cardList.value[index].description !== item.description) {++ // Always update the card data+ cardList.value[index].parse_status = item.parse_status;+ cardList.value[index].summary_status = item.summary_status;+ cardList.value[index].description = item.description;+ hasChanges = true;+ }});}+ // If there are no changes, the watch won't trigger, so we must manually poll again+ // Even if there are changes, we can manually poll again just to be safe.+ // The watch will clear this timeout if it triggers.+ const stillPending = cardList.value.filter(item => {+ const isParsing = item.parse_status == 'pending' || item.parse_status == 'processing';+ const isSummaryPending = item.parse_status == 'completed' &&+ (item.summary_status == 'pending' || item.summary_status == 'processing');+ return isParsing || isSummaryPending;+ });+ if (stillPending.length > 0) {+ updateStatus(stillPending);+ }}).catch((_err) => {// 错误处理+ const stillPending = cardList.value.filter(item => {+ const isParsing = item.parse_status == 'pending' || item.parse_status == 'processing';+ const isSummaryPending = item.parse_status == 'completed' &&+ (item.summary_status == 'pending' || item.summary_status == 'processing');+ return isParsing || isSummaryPending;+ });+ if (stillPending.length > 0) {+ updateStatus(stillPending);+ }});}, 1500);};diff --git a/internal/utils/security.go b/internal/utils/security.goindex 28bc2666f..139434f5a 100644--- a/internal/utils/security.go+++ b/internal/utils/security.go@@ -162,8 +162,8 @@ func IsValidURL(url string) bool {return false}- // 检查协议, 只允许 http, https, local, minio, cos, tos 协议- allowedProtocols := []string{"http://", "https://", "local://", "minio://", "cos://", "tos://"}+ // 检查协议, 只允许 http, https, local, minio, cos, tos, oss 协议+ allowedProtocols := []string{"http://", "https://", "local://", "minio://", "cos://", "tos://", "oss://"}isAllowed := falsefor _, protocol := range allowedProtocols {if strings.HasPrefix(strings.ToLower(url), protocol) {