fix(IOS-INFO-043): move triggerParse inside MaterialReaderView struct
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
123efb1612
commit
042256913e
@ -558,6 +558,28 @@ struct MaterialReaderView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Parse Trigger
|
||||||
|
|
||||||
|
private func triggerParse(kbId: String, sourceId: String) async {
|
||||||
|
guard !isParsing else { return }
|
||||||
|
isParsing = true
|
||||||
|
parseMessage = "正在整理知识点..."
|
||||||
|
do {
|
||||||
|
let result = try await KnowledgeSourceService.shared.parse(kbId: kbId, sourceId: sourceId)
|
||||||
|
parseMessage = "知识点整理任务已提交"
|
||||||
|
for _ in 0..<60 {
|
||||||
|
try await Task.sleep(nanoseconds: 2_000_000_000)
|
||||||
|
let status = try await DocumentImportService.shared.getStatus(id: result.jobId ?? result.id ?? "")
|
||||||
|
if status.status == "completed" { parseMessage = "知识点整理完成"; break }
|
||||||
|
else if status.status == "failed" { parseMessage = "整理失败"; break }
|
||||||
|
else { parseMessage = "整理中... \(status.progress ?? 0)%" }
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
parseMessage = "整理失败: \(error.localizedDescription)"
|
||||||
|
}
|
||||||
|
isParsing = false
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Unsupported
|
// MARK: - Unsupported
|
||||||
|
|
||||||
var unsupportedBody: some View {
|
var unsupportedBody: some View {
|
||||||
@ -731,36 +753,6 @@ private func formatDuration(_ seconds: Int) -> String {
|
|||||||
return "\(seconds / 3600)h\(String(format: "%02d", (seconds % 3600) / 60))m"
|
return "\(seconds / 3600)h\(String(format: "%02d", (seconds % 3600) / 60))m"
|
||||||
}
|
}
|
||||||
|
|
||||||
private func triggerParse(kbId: String, sourceId: String) async {
|
|
||||||
guard !isParsing else { return }
|
|
||||||
isParsing = true
|
|
||||||
parseMessage = "正在整理知识点..."
|
|
||||||
print("[MaterialReader] triggerParse START kbId=\(kbId) sourceId=\(sourceId)")
|
|
||||||
do {
|
|
||||||
let result = try await KnowledgeSourceService.shared.parse(kbId: kbId, sourceId: sourceId)
|
|
||||||
print("[MaterialReader] parse queued: id=\(result.jobId ?? "?"), status=\(result.status ?? "?")")
|
|
||||||
parseMessage = "知识点整理任务已提交"
|
|
||||||
// Poll status
|
|
||||||
for _ in 0..<60 {
|
|
||||||
try await Task.sleep(nanoseconds: 2_000_000_000)
|
|
||||||
let status = try await DocumentImportService.shared.getStatus(id: result.jobId ?? result.id ?? "")
|
|
||||||
print("[MaterialReader] parse status: \(status.status ?? "?")")
|
|
||||||
if status.status == "completed" {
|
|
||||||
parseMessage = "知识点整理完成"
|
|
||||||
break
|
|
||||||
} else if status.status == "failed" {
|
|
||||||
parseMessage = "整理失败: \(status.errorMessage ?? "未知错误")"
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
parseMessage = "整理中... \(status.progress ?? 0)%"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
print("[MaterialReader] triggerParse ERROR: \(error.localizedDescription)")
|
|
||||||
parseMessage = "整理失败: \(error.localizedDescription)"
|
|
||||||
}
|
|
||||||
isParsing = false
|
|
||||||
}
|
|
||||||
|
|
||||||
private func formatFileSize(_ bytes: UInt64) -> String {
|
private func formatFileSize(_ bytes: UInt64) -> String {
|
||||||
if bytes < 1024 { return "\(bytes) B" }
|
if bytes < 1024 { return "\(bytes) B" }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user