feat: 添加腾讯云COS Token管理功能及相关视图更新
- 在APIEndpoints.swift中新增tcToken端点以支持腾讯云COS Token获取。 - 在APIModels.swift中新增TcTokenRequest和TcTokenResponse模型,处理Token请求和响应。 - 在COSManager.swift中实现Token的获取、缓存和过期管理逻辑,提升API请求的安全性。 - 在LanguageSettingsView中添加调试功能,允许测试COS Token获取。 - 在多个视图中更新状态管理和导航逻辑,确保用户体验一致性。 - 在FeedFeature和HomeFeature中优化状态管理,简化视图逻辑。
This commit is contained in:
@@ -661,3 +661,64 @@ struct APIResponse<T: Codable>: Codable {
|
||||
|
||||
// 注意:String+MD5 扩展已移至 Utils/Extensions/String+MD5.swift
|
||||
|
||||
// MARK: - 腾讯云 COS Token 相关模型
|
||||
|
||||
/// 腾讯云 COS Token 请求模型
|
||||
struct TcTokenRequest: APIRequestProtocol {
|
||||
typealias Response = TcTokenResponse
|
||||
|
||||
let endpoint: String = APIEndpoint.tcToken.path
|
||||
let method: HTTPMethod = .GET
|
||||
let queryParameters: [String: String]? = nil
|
||||
var bodyParameters: [String: Any]? { nil }
|
||||
let timeout: TimeInterval = 30.0
|
||||
let includeBaseParameters: Bool = true
|
||||
let shouldShowLoading: Bool = false // 不显示 loading,避免影响用户体验
|
||||
let shouldShowError: Bool = false // 不显示错误,静默处理
|
||||
}
|
||||
|
||||
/// 腾讯云 COS Token 响应模型
|
||||
struct TcTokenResponse: Codable, Equatable {
|
||||
let code: Int
|
||||
let message: String
|
||||
let data: TcTokenData?
|
||||
let timestamp: Int64
|
||||
}
|
||||
|
||||
/// 腾讯云 COS Token 数据模型
|
||||
/// 包含完整的腾讯云 COS 配置信息
|
||||
struct TcTokenData: Codable, Equatable {
|
||||
let bucket: String // 存储桶名称
|
||||
let sessionToken: String // 临时会话令牌
|
||||
let region: String // 地域
|
||||
let customDomain: String // 自定义域名
|
||||
let accelerate: Bool // 是否启用加速
|
||||
let appId: String // 应用 ID
|
||||
let secretKey: String // 临时密钥
|
||||
let expireTime: Int64 // 过期时间戳
|
||||
let startTime: Int64 // 开始时间戳
|
||||
let secretId: String // 临时密钥 ID
|
||||
|
||||
/// 检查 Token 是否已过期
|
||||
var isExpired: Bool {
|
||||
let currentTime = Int64(Date().timeIntervalSince1970)
|
||||
return currentTime >= expireTime
|
||||
}
|
||||
|
||||
/// 获取过期时间
|
||||
var expirationDate: Date {
|
||||
return Date(timeIntervalSince1970: TimeInterval(expireTime))
|
||||
}
|
||||
|
||||
/// 获取开始时间
|
||||
var startDate: Date {
|
||||
return Date(timeIntervalSince1970: TimeInterval(startTime))
|
||||
}
|
||||
|
||||
/// 获取剩余有效时间(秒)
|
||||
var remainingTime: Int64 {
|
||||
let currentTime = Int64(Date().timeIntervalSince1970)
|
||||
return max(0, expireTime - currentTime)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user