debug(IOS-INFO-041): add print logging to ImportPage handleFiles
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
f7d10f3f44
commit
488db840cb
@ -1282,22 +1282,40 @@ struct ImportPage: View {
|
|||||||
private func handleFiles(_ urls: [URL]) async {
|
private func handleFiles(_ urls: [URL]) async {
|
||||||
guard let kb = await ensureKB() else { importError = "请先创建一个知识库"; return }
|
guard let kb = await ensureKB() else { importError = "请先创建一个知识库"; return }
|
||||||
isImporting = true; importError = nil
|
isImporting = true; importError = nil
|
||||||
|
print("[ImportPage] handleFiles count=\(urls.count), kbId=\(kb)")
|
||||||
for url in urls {
|
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() }
|
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
|
let name = url.lastPathComponent
|
||||||
statusMessage = "上传 \(name)..."
|
statusMessage = "上传 \(name)..."
|
||||||
do {
|
do {
|
||||||
let mime = url.pathExtension.lowercased() == "pdf" ? "application/pdf" : "text/plain"
|
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)..."
|
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) 导入任务已创建"
|
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 = ""
|
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 {
|
private func handlePhoto(_ item: PhotosPickerItem) async {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user