feat: 更新API相关逻辑及视图结构
- 在Info.plist中新增API签名密钥配置。 - 将Splash视图替换为SplashV2,优化启动逻辑和用户体验。 - 更新API请求中的User-Agent逻辑,使用UserAgentProvider提供的动态值。 - 在APILogger中添加敏感信息脱敏处理,增强安全性。 - 新增CreateFeedPage视图,支持用户发布动态功能。 - 更新MainPage和Splash视图的导航逻辑,整合统一的AppRoute管理。 - 移除冗余的SplashFeature视图,提升代码整洁性和可维护性。
This commit is contained in:
38
yana/Utils/Network/APIService+Combine.swift
Normal file
38
yana/Utils/Network/APIService+Combine.swift
Normal file
@@ -0,0 +1,38 @@
|
||||
import Foundation
|
||||
@preconcurrency import Combine
|
||||
|
||||
// 以 @unchecked Sendable 包装 Future 的 promise,安全地跨并发域传递
|
||||
private final class PromiseBox<Output, Failure: Error>: @unchecked Sendable {
|
||||
private let fulfill: (Result<Output, Failure>) -> Void
|
||||
init(_ fulfill: @escaping (Result<Output, Failure>) -> Void) { self.fulfill = fulfill }
|
||||
func complete(_ result: Result<Output, Failure>) { fulfill(result) }
|
||||
}
|
||||
|
||||
extension APIServiceProtocol {
|
||||
/// 将 async/await 的请求桥接为 Combine Publisher
|
||||
/// - Parameter request: 符合 APIRequestProtocol 的请求对象
|
||||
/// - Returns: AnyPublisher<T.Response, APIError>
|
||||
func requestPublisher<T: APIRequestProtocol>(_ request: T) -> AnyPublisher<T.Response, APIError> {
|
||||
Deferred {
|
||||
Future { promise in
|
||||
let box = PromiseBox<T.Response, APIError>(promise)
|
||||
Task(priority: .userInitiated) {
|
||||
let result: Result<T.Response, APIError>
|
||||
do {
|
||||
let value = try await self.request(request)
|
||||
result = .success(value)
|
||||
} catch let apiError as APIError {
|
||||
result = .failure(apiError)
|
||||
} catch {
|
||||
result = .failure(.unknown(error.localizedDescription))
|
||||
}
|
||||
box.complete(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
.subscribe(on: DispatchQueue.global(qos: .userInitiated))
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user