diff --git a/frontend/src/components/UploadConfirmHost.vue b/frontend/src/components/UploadConfirmHost.vue index 74f4690e..b7aa343f 100644 --- a/frontend/src/components/UploadConfirmHost.vue +++ b/frontend/src/components/UploadConfirmHost.vue @@ -25,6 +25,7 @@ const handleCancel = () => { :reparse-preview="uploadConfirmStore.reparse" :accept-file-types="uploadConfirmStore.acceptFileTypes" :supported-file-types="uploadConfirmStore.supportedFileTypes" + :target-folder="uploadConfirmStore.targetFolder" @confirm="handleConfirm" @cancel="handleCancel" /> diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index bbc716c5..487b909c 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -371,10 +371,11 @@ export default { tagEditNoSelected: 'None selected', folderTree: { title: 'Folders', - allDocuments: 'All documents', - rootFolder: 'Root', - empty: 'Upload a folder and its structure shows up here.', - includeSubfolders: 'Include documents in sub-folders', + rootRow: 'All documents', + rootRowTip: 'The top level of the knowledge base; every folder sits below it', + scopeToggle: 'Change list scope', + scopeSubtreeTip: 'Including sub-folders — click to list only this level', + scopeDirectTip: 'Listing only this level — click to include sub-folders', collapse: 'Collapse folders', expand: 'Expand folders', collapseFolder: 'Collapse this folder', @@ -668,6 +669,11 @@ export default { description: 'Useful for web-print, scanned, or image-heavy PDFs. Every page will be rendered as an image and processed via OCR/VLM. May increase processing time and model costs.' }, continueAdd: 'Add more', + destinationLabel: 'Upload to', + destinationRoot: 'Knowledge base top level', + destinationRootTip: 'Files go to the top level of the knowledge base, not into any folder', + destinationTip: 'Files go into the folder "{folder}"', + destinationToRoot: 'Upload to the top level instead', filesAdded: 'Added {count} file(s)', filesAllDuplicate: 'Selected files are already in the list', titleManual: 'Confirm online publish', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 6810b8ae..33857455 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -5097,6 +5097,11 @@ export default { vlmModelSelectRequired: '멀티모달이 활성화되었습니다. VLM 모델을 선택하세요', asrModelSelectRequired: '음성 인식이 활성화되었습니다. ASR 모델을 선택하세요', continueAdd: '계속 추가', + destinationLabel: '업로드 위치', + destinationRoot: '지식 베이스 최상위', + destinationRootTip: '파일이 폴더가 아닌 지식 베이스 최상위에 업로드됩니다', + destinationTip: '파일이 「{folder}」 폴더에 업로드됩니다', + destinationToRoot: '최상위에 업로드하도록 변경', filesAdded: '{count}개 파일이 추가되었습니다', filesAllDuplicate: '선택한 파일이 이미 목록에 있습니다', titleManual: '온라인 편집 게시 확인', @@ -5125,10 +5130,11 @@ export default { tagEditNoSelected: '선택 없음', folderTree: { title: '폴더', - allDocuments: '전체 문서', - rootFolder: '루트', - empty: '폴더를 업로드하면 구조가 여기에 표시됩니다.', - includeSubfolders: '하위 폴더의 문서 포함', + rootRow: '전체 문서', + rootRowTip: '지식 베이스의 최상위이며 모든 폴더가 그 아래에 있습니다', + scopeToggle: '목록 범위 변경', + scopeSubtreeTip: '하위 폴더 포함 중 — 클릭하면 이 단계만 표시합니다', + scopeDirectTip: '이 단계만 표시 중 — 클릭하면 하위 폴더를 포함합니다', collapse: '폴더 접기', expand: '폴더 펼치기', collapseFolder: '이 폴더 접기', diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 304ca63c..4ffee273 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -5097,6 +5097,11 @@ export default { vlmModelSelectRequired: 'Мультимодальность включена. Выберите модель VLM.', asrModelSelectRequired: 'Распознавание речи включено. Выберите модель ASR.', continueAdd: 'Добавить ещё', + destinationLabel: 'Загрузить в', + destinationRoot: 'Верхний уровень базы знаний', + destinationRootTip: 'Файлы попадут на верхний уровень базы знаний, вне папок', + destinationTip: 'Файлы попадут в папку «{folder}»', + destinationToRoot: 'Загрузить на верхний уровень', filesAdded: 'Добавлено файлов: {count}', filesAllDuplicate: 'Выбранные файлы уже в списке', titleManual: 'Подтверждение публикации', @@ -5125,10 +5130,11 @@ export default { tagEditNoSelected: 'Ничего не выбрано', folderTree: { title: 'Папки', - allDocuments: 'Все документы', - rootFolder: 'Корень', - empty: 'Загрузите папку — её структура появится здесь.', - includeSubfolders: 'Включать документы во вложенных папках', + rootRow: 'Все документы', + rootRowTip: 'Верхний уровень базы знаний — все папки находятся внутри него', + scopeToggle: 'Изменить область списка', + scopeSubtreeTip: 'Вложенные папки включены — нажмите, чтобы показать только этот уровень', + scopeDirectTip: 'Показан только этот уровень — нажмите, чтобы включить вложенные папки', collapse: 'Свернуть папки', expand: 'Развернуть папки', collapseFolder: 'Свернуть эту папку', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index d5e993d8..8c85bc3c 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -5097,6 +5097,11 @@ export default { vlmModelSelectRequired: '已启用多模态,请选择 VLM 模型', asrModelSelectRequired: '已启用语音识别,请选择 ASR 模型', continueAdd: '继续添加', + destinationLabel: '上传到', + destinationRoot: '知识库顶层', + destinationRootTip: '文件将上传到知识库顶层,不放入任何文件夹', + destinationTip: '文件将上传到文件夹「{folder}」', + destinationToRoot: '改为上传到顶层', filesAdded: '已添加 {count} 个文件', filesAllDuplicate: '所选文件已在列表中', titleManual: '在线编辑发布确认', @@ -5125,10 +5130,11 @@ export default { tagEditNoSelected: '暂未选择', folderTree: { title: '目录', - allDocuments: '全部文档', - rootFolder: '根目录', - empty: '上传文件夹后,目录结构会显示在这里。', - includeSubfolders: '包含子目录中的文档', + rootRow: '全部文档', + rootRowTip: '知识库顶层,所有文件夹都在它下面', + scopeToggle: '切换列表范围', + scopeSubtreeTip: '当前包含子目录,点击改为仅显示本层文档', + scopeDirectTip: '当前仅显示本层文档,点击改为包含子目录', collapse: '收起目录', expand: '展开目录', collapseFolder: '收起该文件夹', diff --git a/frontend/src/stores/uploadConfirm.ts b/frontend/src/stores/uploadConfirm.ts index 350bd4dd..7ba3223f 100644 --- a/frontend/src/stores/uploadConfirm.ts +++ b/frontend/src/stores/uploadConfirm.ts @@ -26,6 +26,13 @@ export interface UploadConfirmResult { urls?: string[] manual?: UploadConfirmManualSource reparse?: UploadConfirmReparseSource + /** + * Folder the batch is uploaded into ('' = knowledge base root). Returned as + * part of the result because the dialog lets the user change it, so callers + * must use this value rather than whatever folder was open when they opened + * the dialog. + */ + targetFolder?: string } export interface OpenUploadConfirmOptions { @@ -38,6 +45,8 @@ export interface OpenUploadConfirmOptions { reparse?: UploadConfirmReparseSource acceptFileTypes?: string supportedFileTypes?: string[] + /** Folder pre-selected from the sidebar tree; '' means the root. */ + targetFolder?: string } export const useUploadConfirmStore = defineStore('uploadConfirm', { @@ -52,6 +61,7 @@ export const useUploadConfirmStore = defineStore('uploadConfirm', { reparse: null as UploadConfirmReparseSource | null, acceptFileTypes: '', supportedFileTypes: [] as string[], + targetFolder: '', pendingResolve: null as ((value: UploadConfirmResult) => void) | null, pendingReject: null as (() => void) | null, }), @@ -71,6 +81,7 @@ export const useUploadConfirmStore = defineStore('uploadConfirm', { this.reparse = options.reparse || null this.acceptFileTypes = options.acceptFileTypes || '' this.supportedFileTypes = options.supportedFileTypes ? [...options.supportedFileTypes] : [] + this.targetFolder = options.targetFolder || '' this.pendingResolve = resolve this.pendingReject = reject }) @@ -97,6 +108,7 @@ export const useUploadConfirmStore = defineStore('uploadConfirm', { this.reparse = null this.acceptFileTypes = '' this.supportedFileTypes = [] + this.targetFolder = '' this.pendingResolve = null this.pendingReject = null }, diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue index 8af91b09..acd03a9d 100644 --- a/frontend/src/views/knowledge/KnowledgeBase.vue +++ b/frontend/src/views/knowledge/KnowledgeBase.vue @@ -63,6 +63,7 @@ import { folderBreadcrumbs as buildFolderBreadcrumbs, folderPathExists as folderExistsInTree, isFolderUpload, + ROOT_FOLDER_PATH, } from './folderTree'; import { useI18n } from 'vue-i18n'; import { useMarqueeSelect } from '@/hooks/useMarqueeSelect'; @@ -604,11 +605,12 @@ const disableFutureDate = { after: new Date(new Date().setHours(23, 59, 59, 999) // ── Folder tree (documents uploaded as a folder keep their relative path) ── const FOLDER_TREE_COLLAPSED_KEY = 'weknora.kbFolderTreeCollapsed'; const FOLDER_TREE_RECURSIVE_KEY = 'weknora.kbFolderRecursive'; -const readStoredFlag = (key: string) => { +const readStoredFlag = (key: string, fallback = false) => { try { - return localStorage.getItem(key) === 'true'; + const raw = localStorage.getItem(key); + return raw === null ? fallback : raw === 'true'; } catch { - return false; + return fallback; } }; const writeStoredFlag = (key: string, value: boolean) => { @@ -620,23 +622,22 @@ const writeStoredFlag = (key: string, value: boolean) => { }; const folderTree = ref(null); const folderTreeLoading = ref(false); -// `null` browses every folder (the historical flat list), `''` is the knowledge -// base root, any other value is a folder path. -const selectedFolderPath = ref(null); +// The selected folder path; ROOT_FOLDER_PATH ('') is the knowledge base root, +// which is a real node of the tree rather than a separate "all documents" mode. +// Combined with folderRecursive it covers both "everything" (root + recursive) +// and "documents not inside any folder" (root + direct only). +const selectedFolderPath = ref(ROOT_FOLDER_PATH); const folderTreeCollapsed = ref(readStoredFlag(FOLDER_TREE_COLLAPSED_KEY)); -const folderRecursive = ref(readStoredFlag(FOLDER_TREE_RECURSIVE_KEY)); +// Recursive by default: a freshly opened knowledge base should list everything, +// and a folder that only holds sub-folders would otherwise look empty. +const folderRecursive = ref(readStoredFlag(FOLDER_TREE_RECURSIVE_KEY, true)); const hasFolders = computed(() => (folderTree.value?.folders?.length ?? 0) > 0); // The folder column only earns its space once the knowledge base actually has // folders, so knowledge bases filled with single-file uploads look unchanged. -const showFolderTree = computed(() => !isFAQ.value && (hasFolders.value || selectedFolderPath.value !== null)); +const showFolderTree = computed(() => !isFAQ.value && hasFolders.value); // Rows only need their folder shown when the current list can span folders. -const showDocumentFolderPath = computed( - () => hasFolders.value && (selectedFolderPath.value === null || folderRecursive.value), -); +const showDocumentFolderPath = computed(() => hasFolders.value && folderRecursive.value); const folderBreadcrumbs = computed(() => buildFolderBreadcrumbs(selectedFolderPath.value)); -// Uploads land in the folder currently being browsed; "all documents" and the -// root row both mean "no prefix". -const uploadTargetFolder = computed(() => selectedFolderPath.value || ''); const filterParams = computed(() => { const [start, end] = updatedTimeRange.value || []; @@ -648,7 +649,9 @@ const filterParams = computed(() => { source: selectedSource.value || undefined, start_time: start ? `${start} 00:00:00` : undefined, end_time: end ? `${end} 23:59:59` : undefined, - folder_path: selectedFolderPath.value === null ? undefined : selectedFolderPath.value, + // The root folder with the recursive scope is equivalent to no folder filter + // at all, so knowledge bases without folders behave exactly as before. + folder_path: selectedFolderPath.value, folder_recursive: folderRecursive.value, }; }); @@ -761,10 +764,9 @@ const loadFolderTree = async (kbIdValue: string) => { if (!isCurrentKb(kbIdValue)) return; folderTree.value = (res?.data as KnowledgeFolderTree) || null; // A folder can disappear (its last document was deleted or moved); fall - // back to the flat list instead of leaving an empty, unreachable view. - const path = selectedFolderPath.value; - if (path && !folderExistsInTree(folderTree.value?.folders || [], path)) { - selectedFolderPath.value = null; + // back to the root instead of leaving an empty, unreachable view. + if (!folderExistsInTree(folderTree.value?.folders || [], selectedFolderPath.value)) { + selectedFolderPath.value = ROOT_FOLDER_PATH; } } catch (error) { if (!isCurrentKb(kbIdValue)) return; @@ -777,7 +779,7 @@ const loadFolderTree = async (kbIdValue: string) => { } }; -const handleFolderSelect = (path: string | null) => { +const handleFolderSelect = (path: string) => { if (selectedFolderPath.value === path) return; selectedFolderPath.value = path; }; @@ -1030,7 +1032,7 @@ watch(() => kbId.value, (newKbId, oldKbId) => { tagPage.value = 1; uiStore.clearSelectedTagIds(); folderTree.value = null; - selectedFolderPath.value = null; + selectedFolderPath.value = ROOT_FOLDER_PATH; } loadKnowledgeBaseInfo(newKbId); }, { immediate: true }); @@ -1507,8 +1509,8 @@ const AUDIO_EXTENSIONS = ['mp3', 'wav', 'm4a', 'flac', 'ogg']; const uploadConfirmStore = useUploadConfirmStore(); -const getFolderUploadFileName = (file: File) => - buildUploadFileName(file, uploadTargetFolder.value); +const getFolderUploadFileName = (file: File, targetFolder: string) => + buildUploadFileName(file, targetFolder); const showUploadResultMessages = ( successCount: number, @@ -1545,7 +1547,12 @@ const showUploadResultMessages = ( const executeUploadBatch = async ( files: File[], - options: { processConfig?: KnowledgeProcessOverrides; tagIds?: string[] } = {}, + options: { + processConfig?: KnowledgeProcessOverrides; + tagIds?: string[]; + /** Destination folder confirmed in the upload dialog; '' is the root. */ + targetFolder?: string; + } = {}, ) => { const targetKbId = kbId.value; if (!targetKbId || files.length === 0) { @@ -1569,7 +1576,7 @@ const executeUploadBatch = async ( process_config?: KnowledgeProcessOverrides } = { file, tag_ids: tagIdsToUpload }; - const fileName = getFolderUploadFileName(file); + const fileName = getFolderUploadFileName(file, options.targetFolder || ROOT_FOLDER_PATH); if (fileName) uploadData.fileName = fileName; if (options.processConfig) { uploadData.process_config = options.processConfig; @@ -1676,7 +1683,11 @@ const handleUploadConfirmResult = async (result: UploadConfirmResult) => { if (hasFolderPaths) { MessagePlugin.info(t('knowledgeBase.uploadingFolder', { total: files.length })); } - await executeUploadBatch(files, { processConfig, tagIds }); + await executeUploadBatch(files, { + processConfig, + tagIds, + targetFolder: result.targetFolder || ROOT_FOLDER_PATH, + }); } for (const url of urls) { @@ -1696,6 +1707,9 @@ const openUploadConfirmDialog = async (files: File[], urls: string[] = []) => { urls, acceptFileTypes: acceptFileTypes.value, supportedFileTypes: [...supportedFileTypes.value], + // Pre-fill the destination with the folder being browsed; the dialog shows + // it and lets the user send the batch to the root instead. + targetFolder: selectedFolderPath.value, }); await handleUploadConfirmResult(result); } catch { @@ -2252,14 +2266,11 @@ async function createNewSession(value: string): Promise { @update:recursive="handleFolderRecursiveChange" />
-