feat: 新增相册自动修图与OTG状态预览
支持相册修图配置、模板选择和传输模式选择;上传后自动提交修图并展示状态角标及精修预览。补充接口文档与相关测试。
This commit is contained in:
@@ -56,6 +56,13 @@ struct TravelAlbumOTGPhotoRecord: Codable, Hashable, Sendable {
|
||||
let albumId: Int
|
||||
let userId: String
|
||||
var remoteUrl: String
|
||||
var serverMaterialId: Int
|
||||
var autoRetouchState: TravelAlbumAutoRetouchState
|
||||
var autoRetouchTemplateId: Int?
|
||||
var autoRetouchClientRequestId: String
|
||||
var autoRetouchBatchId: Int
|
||||
var autoRetouchAttempt: Int
|
||||
var autoRetouchErrorMessage: String?
|
||||
var updatedAt: Int64
|
||||
|
||||
/// 创建 OTG 本地照片记录。
|
||||
@@ -74,6 +81,13 @@ struct TravelAlbumOTGPhotoRecord: Codable, Hashable, Sendable {
|
||||
albumId: Int,
|
||||
userId: String,
|
||||
remoteUrl: String = "",
|
||||
serverMaterialId: Int = 0,
|
||||
autoRetouchState: TravelAlbumAutoRetouchState = .none,
|
||||
autoRetouchTemplateId: Int? = nil,
|
||||
autoRetouchClientRequestId: String = "",
|
||||
autoRetouchBatchId: Int = 0,
|
||||
autoRetouchAttempt: Int = 0,
|
||||
autoRetouchErrorMessage: String? = nil,
|
||||
updatedAt: Int64 = Int64(Date().timeIntervalSince1970 * 1000)
|
||||
) {
|
||||
self.id = id
|
||||
@@ -90,12 +104,22 @@ struct TravelAlbumOTGPhotoRecord: Codable, Hashable, Sendable {
|
||||
self.albumId = albumId
|
||||
self.userId = userId
|
||||
self.remoteUrl = remoteUrl
|
||||
self.serverMaterialId = max(0, serverMaterialId)
|
||||
self.autoRetouchState = autoRetouchState
|
||||
self.autoRetouchTemplateId = autoRetouchTemplateId
|
||||
self.autoRetouchClientRequestId = autoRetouchClientRequestId
|
||||
self.autoRetouchBatchId = max(0, autoRetouchBatchId)
|
||||
self.autoRetouchAttempt = max(0, autoRetouchAttempt)
|
||||
self.autoRetouchErrorMessage = autoRetouchErrorMessage
|
||||
self.updatedAt = updatedAt
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case id, sourceId, clientPhotoId, fileName, localPath, thumbnailPath, capturedAt
|
||||
case fileSizeBytes, status, progress, errorMessage, albumId, userId, remoteUrl, updatedAt
|
||||
case serverMaterialId, autoRetouchState, autoRetouchTemplateId
|
||||
case autoRetouchClientRequestId, autoRetouchBatchId, autoRetouchAttempt
|
||||
case autoRetouchErrorMessage
|
||||
}
|
||||
|
||||
/// 解码本地索引;旧版本缺少 `clientPhotoId` 时先保留为空,由 Store 一次性迁移并回写。
|
||||
@@ -115,16 +139,34 @@ struct TravelAlbumOTGPhotoRecord: Codable, Hashable, Sendable {
|
||||
albumId = try container.decode(Int.self, forKey: .albumId)
|
||||
userId = try container.decode(String.self, forKey: .userId)
|
||||
remoteUrl = try container.decodeIfPresent(String.self, forKey: .remoteUrl) ?? ""
|
||||
serverMaterialId = try container.decodeIfPresent(Int.self, forKey: .serverMaterialId) ?? 0
|
||||
autoRetouchState = try container.decodeIfPresent(
|
||||
TravelAlbumAutoRetouchState.self,
|
||||
forKey: .autoRetouchState
|
||||
) ?? .none
|
||||
autoRetouchTemplateId = try container.decodeIfPresent(Int.self, forKey: .autoRetouchTemplateId)
|
||||
autoRetouchClientRequestId = try container.decodeIfPresent(
|
||||
String.self,
|
||||
forKey: .autoRetouchClientRequestId
|
||||
) ?? ""
|
||||
autoRetouchBatchId = try container.decodeIfPresent(Int.self, forKey: .autoRetouchBatchId) ?? 0
|
||||
autoRetouchAttempt = try container.decodeIfPresent(Int.self, forKey: .autoRetouchAttempt) ?? 0
|
||||
autoRetouchErrorMessage = try container.decodeIfPresent(String.self, forKey: .autoRetouchErrorMessage)
|
||||
updatedAt = try container.decodeIfPresent(Int64.self, forKey: .updatedAt) ?? 0
|
||||
}
|
||||
|
||||
/// 把中断中的传输恢复为待上传,避免重进页面卡在上传中。
|
||||
func normalizedAfterInterruptedTransfer() -> TravelAlbumOTGPhotoRecord {
|
||||
guard status == .transferring || status == .uploading else { return self }
|
||||
var copy = self
|
||||
copy.status = .pending
|
||||
copy.progress = 0
|
||||
copy.errorMessage = nil
|
||||
if status == .transferring || status == .uploading {
|
||||
copy.status = .pending
|
||||
copy.progress = 0
|
||||
copy.errorMessage = nil
|
||||
}
|
||||
if autoRetouchState == .submitting {
|
||||
copy.autoRetouchState = .pendingSubmission
|
||||
}
|
||||
guard copy != self else { return self }
|
||||
copy.updatedAt = Int64(Date().timeIntervalSince1970 * 1000)
|
||||
return copy
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user