fix(IOS-INFO-040): ImportPage now creates KnowledgeSource via add API
- Use uploadDataWithKey to get fileId + objectKey - Call KnowledgeSourceService.add() instead of DocumentImportService.create() - Creates both KnowledgeSource and DocumentImport in one call - Add missing fields to AddSourceRequest and KnowledgeSourceService.add() Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
488db840cb
commit
c5ce70fa5a
@ -636,6 +636,10 @@ struct AddSourceRequest: Codable {
|
|||||||
let fileId: String?
|
let fileId: String?
|
||||||
let type: String?
|
let type: String?
|
||||||
let title: String?
|
let title: String?
|
||||||
|
let originalFilename: String?
|
||||||
|
let mimeType: String?
|
||||||
|
let sizeBytes: Int?
|
||||||
|
let originalObjectKey: String?
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Learning Activity
|
// MARK: - Learning Activity
|
||||||
|
|||||||
@ -538,8 +538,8 @@ class KnowledgeSourceService {
|
|||||||
return try await client.request("/knowledge-bases/\(kbId)/sources/\(id)")
|
return try await client.request("/knowledge-bases/\(kbId)/sources/\(id)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func add(kbId: String, fileId: String? = nil, type: String? = nil, title: String? = nil) async throws -> KnowledgeSource {
|
func add(kbId: String, fileId: String? = nil, type: String? = nil, title: String? = nil, originalFilename: String? = nil, mimeType: String? = nil, sizeBytes: Int? = nil, originalObjectKey: String? = nil) async throws -> KnowledgeSource {
|
||||||
let body = AddSourceRequest(fileId: fileId, type: type, title: title)
|
let body = AddSourceRequest(fileId: fileId, type: type, title: title, originalFilename: originalFilename, mimeType: mimeType, sizeBytes: sizeBytes, originalObjectKey: originalObjectKey)
|
||||||
return try await client.request("/knowledge-bases/\(kbId)/sources", method: "POST", body: body)
|
return try await client.request("/knowledge-bases/\(kbId)/sources", method: "POST", body: body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1300,13 +1300,22 @@ struct ImportPage: View {
|
|||||||
do {
|
do {
|
||||||
let mime = url.pathExtension.lowercased() == "pdf" ? "application/pdf" : "text/plain"
|
let mime = url.pathExtension.lowercased() == "pdf" ? "application/pdf" : "text/plain"
|
||||||
print("[ImportPage] Uploading to COS: \(name), mime=\(mime)")
|
print("[ImportPage] Uploading to COS: \(name), mime=\(mime)")
|
||||||
let uploadResult = try await FileUploadService.shared.uploadData(data, filename: name, mimeType: mime)
|
let (fileId, objectKey) = try await FileUploadService.shared.uploadDataWithKey(data, filename: name, mimeType: mime)
|
||||||
print("[ImportPage] COS upload OK: \(String(describing: uploadResult))")
|
print("[ImportPage] COS upload OK: fileId=\(fileId), objectKey=\(objectKey)")
|
||||||
statusMessage = "开始导入 \(name)..."
|
statusMessage = "创建资料..."
|
||||||
print("[ImportPage] Calling POST /imports: kbId=\(kb), fileName=\(name)")
|
print("[ImportPage] Calling POST /knowledge-bases/\(kb)/sources: fileName=\(name)")
|
||||||
let importResult = try await DocumentImportService.shared.create(knowledgeBaseId: kb, fileName: name, sourceType: "file")
|
let source = try await KnowledgeSourceService.shared.add(
|
||||||
print("[ImportPage] Import created: \(String(describing: importResult))")
|
kbId: kb,
|
||||||
statusMessage = "\(name) 导入任务已创建"
|
fileId: fileId,
|
||||||
|
type: "file",
|
||||||
|
title: name,
|
||||||
|
originalFilename: name,
|
||||||
|
mimeType: mime,
|
||||||
|
sizeBytes: data.count,
|
||||||
|
originalObjectKey: objectKey
|
||||||
|
)
|
||||||
|
print("[ImportPage] Source created: id=\(source.id), title=\(source.title ?? name)")
|
||||||
|
statusMessage = "\(name) 导入完成"
|
||||||
} catch {
|
} catch {
|
||||||
print("[ImportPage] ❌ Error for \(name): \(error.localizedDescription)")
|
print("[ImportPage] ❌ Error for \(name): \(error.localizedDescription)")
|
||||||
print("[ImportPage] Full error: \(error)")
|
print("[ImportPage] Full error: \(error)")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user