From 488db840cb1049074b555ecd5b828ea930fa639b Mon Sep 17 00:00:00 2001 From: wangdl Date: Thu, 18 Jun 2026 22:24:15 +0800 Subject: [PATCH] debug(IOS-INFO-041): add print logging to ImportPage handleFiles Co-Authored-By: Claude Opus 4.7 --- .../Features/Library/LibrarySubpages.swift | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/AIStudyApp/AIStudyApp/Features/Library/LibrarySubpages.swift b/AIStudyApp/AIStudyApp/Features/Library/LibrarySubpages.swift index ae80d7c..76196e3 100644 --- a/AIStudyApp/AIStudyApp/Features/Library/LibrarySubpages.swift +++ b/AIStudyApp/AIStudyApp/Features/Library/LibrarySubpages.swift @@ -1282,22 +1282,40 @@ struct ImportPage: View { private func handleFiles(_ urls: [URL]) async { guard let kb = await ensureKB() else { importError = "请先创建一个知识库"; return } isImporting = true; importError = nil + print("[ImportPage] handleFiles count=\(urls.count), kbId=\(kb)") for url in urls { - guard url.startAccessingSecurityScopedResource() else { continue } + print("[ImportPage] Processing: \(url.lastPathComponent)") + guard url.startAccessingSecurityScopedResource() else { + print("[ImportPage] ❌ startAccessingSecurityScopedResource failed for \(url.lastPathComponent)") + continue + } defer { url.stopAccessingSecurityScopedResource() } - guard let data = try? Data(contentsOf: url) else { continue } + guard let data = try? Data(contentsOf: url) else { + print("[ImportPage] ❌ Data(contentsOf:) failed for \(url.lastPathComponent)") + continue + } + print("[ImportPage] File read OK, size=\(data.count) bytes") let name = url.lastPathComponent statusMessage = "上传 \(name)..." do { let mime = url.pathExtension.lowercased() == "pdf" ? "application/pdf" : "text/plain" - let _ = try await FileUploadService.shared.uploadData(data, filename: name, mimeType: mime) + print("[ImportPage] Uploading to COS: \(name), mime=\(mime)") + let uploadResult = try await FileUploadService.shared.uploadData(data, filename: name, mimeType: mime) + print("[ImportPage] COS upload OK: \(String(describing: uploadResult))") statusMessage = "开始导入 \(name)..." - let _ = try await DocumentImportService.shared.create(knowledgeBaseId: kb, fileName: name, sourceType: "file") + print("[ImportPage] Calling POST /imports: kbId=\(kb), fileName=\(name)") + let importResult = try await DocumentImportService.shared.create(knowledgeBaseId: kb, fileName: name, sourceType: "file") + print("[ImportPage] Import created: \(String(describing: importResult))") statusMessage = "\(name) 导入任务已创建" - } catch { importError = "\(name) 导入失败: \(error.localizedDescription)" } + } catch { + print("[ImportPage] ❌ Error for \(name): \(error.localizedDescription)") + print("[ImportPage] Full error: \(error)") + importError = "\(name) 导入失败: \(error.localizedDescription)" + } } isImporting = false; statusMessage = "" - if importError == nil { ZXToastManager.shared.success("导入完成"); dismiss() } + if importError == nil { print("[ImportPage] ✅ All files imported successfully"); ZXToastManager.shared.success("导入完成"); dismiss() } + else { print("[ImportPage] ⚠️ Import completed with errors: \(importError!)") } } private func handlePhoto(_ item: PhotosPickerItem) async {