feat(drone-dock): 完善真实联调、状态轮询与准备页反馈
开放 Release 真实操作并保留 Debug 拦截;恢复前台 shooting 串行轮询;统一打印机巢请求与完整原值响应;优化长点位名称、未拍摄文案、报备失败及已结束任务提示,移除成功回执 UI。补充相关测试、离线策略检查和联调说明。
This commit is contained in:
@@ -100,18 +100,41 @@ final class ScenicMaterialDownloadService {
|
||||
/// 检查 HTTP 状态与非空响应文件的空境原片下载器。
|
||||
struct ScenicMaterialURLSessionDownloader: CloudFileDownloading {
|
||||
private let session: URLSession
|
||||
private let logSink: @Sendable (String) -> Void
|
||||
|
||||
/// 注入 URLSession 便于使用 URLProtocol 验证状态码及错误响应。
|
||||
init(session: URLSession = .shared) { self.session = session }
|
||||
init(session: URLSession = .shared, logSink: @escaping @Sendable (String) -> Void = DroneDockDiagnostics.write) {
|
||||
self.session = session
|
||||
self.logSink = logSink
|
||||
}
|
||||
|
||||
/// 下载到唯一临时路径;失败响应及取消下载均清理 URLSession 临时文件。
|
||||
func downloadFile(remoteURL: String, fileName: String,
|
||||
onProgress: @escaping @Sendable (Int) -> Void) async throws -> URL {
|
||||
guard let url = URL(string: remoteURL), ["https", "http"].contains(url.scheme?.lowercased() ?? ""),
|
||||
url.host != nil else { throw ScenicMaterialDownloadError.invalidURL }
|
||||
let delegate = ScenicMaterialDownloadProgress(onProgress: onProgress)
|
||||
let (temporaryURL, response) = try await session.download(from: url, delegate: delegate)
|
||||
let trace = DroneDockFileTransferTrace(operation: "file_download", method: "GET", remoteURL: url)
|
||||
logSink(trace.message("request.started"))
|
||||
let temporaryURL: URL
|
||||
let response: URLResponse
|
||||
do {
|
||||
let delegate = ScenicMaterialDownloadProgress(onProgress: onProgress)
|
||||
(temporaryURL, response) = try await session.download(from: url, delegate: delegate)
|
||||
} catch {
|
||||
let cancelled = error is CancellationError || (error as? URLError)?.code == .cancelled
|
||||
logSink(trace.message(cancelled ? "request.cancelled" : "request.failed",
|
||||
fields: DroneDockDiagnostics.errorFields(error)))
|
||||
throw error
|
||||
}
|
||||
defer { try? FileManager.default.removeItem(at: temporaryURL) }
|
||||
let receivedSize = (try? FileManager.default.attributesOfItem(atPath: temporaryURL.path)[.size] as? NSNumber)?.int64Value ?? 0
|
||||
logSink(trace.message("response.received", fields: [
|
||||
"http_status": (response as? HTTPURLResponse)?.statusCode ?? 0,
|
||||
"response_headers": (response as? HTTPURLResponse)?.allHeaderFields.reduce(into: [String: String]()) {
|
||||
$0[String(describing: $1.key)] = String(describing: $1.value)
|
||||
} ?? [:],
|
||||
"bytes": receivedSize, "content_type": response.mimeType ?? "unknown", "body": "<binary omitted>"
|
||||
]))
|
||||
try Task.checkCancellation()
|
||||
guard let response = response as? HTTPURLResponse, (200..<300).contains(response.statusCode) else {
|
||||
throw ScenicMaterialDownloadError.httpFailure((response as? HTTPURLResponse)?.statusCode ?? 0)
|
||||
|
||||
Reference in New Issue
Block a user