feat: add AI retouch and album preview actions
This commit is contained in:
@@ -127,6 +127,10 @@ struct TravelAlbumMaterial: Decodable, Sendable, Equatable, Hashable, Identifiab
|
||||
let fileSize: Int
|
||||
let coverUrl: String
|
||||
let isPurchased: Bool
|
||||
let aiRetouchStatus: Int
|
||||
let aiRetouchStatusName: String
|
||||
let aiRefinedURL: String
|
||||
let aiAtmosphereURL: String
|
||||
let createdAt: String
|
||||
let updatedAt: String
|
||||
|
||||
@@ -142,10 +146,40 @@ struct TravelAlbumMaterial: Decodable, Sendable, Equatable, Hashable, Identifiab
|
||||
case fileSize = "file_size"
|
||||
case coverUrl = "cover_url"
|
||||
case isPurchased = "is_purchased"
|
||||
case aiRetouchStatus = "ai_retouch_status"
|
||||
case aiRetouchStatusName = "ai_retouch_status_name"
|
||||
case aiRefinedURL = "ai_refined_url"
|
||||
case aiAtmosphereURL = "ai_atmosphere_url"
|
||||
case createdAt = "created_at"
|
||||
case updatedAt = "updated_at"
|
||||
}
|
||||
|
||||
/// 从素材接口解码;AI 修图扩展字段缺失、为空或类型异常时使用安全默认值。
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = try container.decode(Int.self, forKey: .id)
|
||||
userEquityTravelId = try container.decode(Int.self, forKey: .userEquityTravelId)
|
||||
status = try container.decode(Int.self, forKey: .status)
|
||||
orderNumber = try container.decode(String.self, forKey: .orderNumber)
|
||||
userId = try container.decode(Int.self, forKey: .userId)
|
||||
fileName = try container.decode(String.self, forKey: .fileName)
|
||||
fileType = try container.decode(Int.self, forKey: .fileType)
|
||||
fileUrl = try container.decode(String.self, forKey: .fileUrl)
|
||||
fileSize = try container.decode(Int.self, forKey: .fileSize)
|
||||
coverUrl = try container.decode(String.self, forKey: .coverUrl)
|
||||
isPurchased = try container.decode(Bool.self, forKey: .isPurchased)
|
||||
aiRetouchStatus = (try? container.decodeIfPresent(Int.self, forKey: .aiRetouchStatus)) ?? 0
|
||||
aiRetouchStatusName = (
|
||||
try? container.decodeIfPresent(String.self, forKey: .aiRetouchStatusName)
|
||||
) ?? ""
|
||||
aiRefinedURL = (try? container.decodeIfPresent(String.self, forKey: .aiRefinedURL)) ?? ""
|
||||
aiAtmosphereURL = (
|
||||
try? container.decodeIfPresent(String.self, forKey: .aiAtmosphereURL)
|
||||
) ?? ""
|
||||
createdAt = try container.decode(String.self, forKey: .createdAt)
|
||||
updatedAt = try container.decode(String.self, forKey: .updatedAt)
|
||||
}
|
||||
|
||||
init(
|
||||
id: Int = 0,
|
||||
userEquityTravelId: Int = 0,
|
||||
@@ -158,6 +192,10 @@ struct TravelAlbumMaterial: Decodable, Sendable, Equatable, Hashable, Identifiab
|
||||
fileSize: Int = 0,
|
||||
coverUrl: String = "",
|
||||
isPurchased: Bool = false,
|
||||
aiRetouchStatus: Int = 0,
|
||||
aiRetouchStatusName: String = "",
|
||||
aiRefinedURL: String = "",
|
||||
aiAtmosphereURL: String = "",
|
||||
createdAt: String = "",
|
||||
updatedAt: String = ""
|
||||
) {
|
||||
@@ -172,11 +210,68 @@ struct TravelAlbumMaterial: Decodable, Sendable, Equatable, Hashable, Identifiab
|
||||
self.fileSize = fileSize
|
||||
self.coverUrl = coverUrl
|
||||
self.isPurchased = isPurchased
|
||||
self.aiRetouchStatus = aiRetouchStatus
|
||||
self.aiRetouchStatusName = aiRetouchStatusName
|
||||
self.aiRefinedURL = aiRefinedURL
|
||||
self.aiAtmosphereURL = aiAtmosphereURL
|
||||
self.createdAt = createdAt
|
||||
self.updatedAt = updatedAt
|
||||
}
|
||||
}
|
||||
|
||||
/// 相册素材网格角标类别,用于稳定映射文案优先级和语义颜色。
|
||||
enum TravelAlbumMaterialBadgeKind: Sendable, Equatable {
|
||||
case purchased
|
||||
case pending
|
||||
case processing
|
||||
case retouched
|
||||
case cover
|
||||
case failed
|
||||
}
|
||||
|
||||
/// 相册素材网格角标展示内容。
|
||||
struct TravelAlbumMaterialBadgePresentation: Sendable, Equatable {
|
||||
let kind: TravelAlbumMaterialBadgeKind
|
||||
let text: String
|
||||
}
|
||||
|
||||
extension TravelAlbumMaterial {
|
||||
/// 按 AI 修图状态和购买状态生成网格角标;返回 nil 时隐藏角标。
|
||||
var badgePresentation: TravelAlbumMaterialBadgePresentation? {
|
||||
if aiRetouchStatus == 0 {
|
||||
return isPurchased
|
||||
? TravelAlbumMaterialBadgePresentation(kind: .purchased, text: "已购")
|
||||
: nil
|
||||
}
|
||||
|
||||
let statusName = aiRetouchStatusName.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
switch aiRetouchStatus {
|
||||
case 1:
|
||||
return TravelAlbumMaterialBadgePresentation(
|
||||
kind: .pending,
|
||||
text: statusName.isEmpty ? "待处理" : statusName
|
||||
)
|
||||
case 2:
|
||||
return TravelAlbumMaterialBadgePresentation(
|
||||
kind: .processing,
|
||||
text: statusName.isEmpty ? "修图中" : statusName
|
||||
)
|
||||
case 3:
|
||||
return TravelAlbumMaterialBadgePresentation(
|
||||
kind: statusName == "AI封面" ? .cover : .retouched,
|
||||
text: statusName.isEmpty ? "AI已修" : statusName
|
||||
)
|
||||
case 4:
|
||||
return TravelAlbumMaterialBadgePresentation(
|
||||
kind: .failed,
|
||||
text: statusName.isEmpty ? "失败" : statusName
|
||||
)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 旅拍相册创建请求体,对齐 Android `TravelAlbumCreateRequest`。
|
||||
struct TravelAlbumCreateRequest: Encodable, Sendable, Equatable {
|
||||
let name: String
|
||||
@@ -247,6 +342,67 @@ struct TravelAlbumMpCodeResponse: Decodable, Sendable, Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
/// AI 修图模板,包含业务 ID、展示名称和预览图地址。
|
||||
struct TravelAlbumAIRetouchTemplate: Decodable, Sendable, Equatable, Hashable, Identifiable {
|
||||
let id: Int
|
||||
let name: String
|
||||
let previewURL: String
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case name
|
||||
case previewURL = "preview_url"
|
||||
}
|
||||
|
||||
/// 创建 AI 修图模板。
|
||||
init(id: Int, name: String, previewURL: String) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.previewURL = previewURL
|
||||
}
|
||||
}
|
||||
|
||||
/// AI 修图模板接口响应,按原图、氛围感和封面风格分组。
|
||||
struct TravelAlbumAIRetouchTemplatesResponse: Decodable, Sendable, Equatable {
|
||||
let refinedTemplates: [TravelAlbumAIRetouchTemplate]
|
||||
let atmosphereTemplates: [TravelAlbumAIRetouchTemplate]
|
||||
let coverTemplates: [TravelAlbumAIRetouchTemplate]
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case refinedTemplates = "refined_templates"
|
||||
case atmosphereTemplates = "atmosphere_templates"
|
||||
case coverTemplates = "cover_templates"
|
||||
}
|
||||
|
||||
/// 创建分组模板响应,默认各组为空。
|
||||
init(
|
||||
refinedTemplates: [TravelAlbumAIRetouchTemplate] = [],
|
||||
atmosphereTemplates: [TravelAlbumAIRetouchTemplate] = [],
|
||||
coverTemplates: [TravelAlbumAIRetouchTemplate] = []
|
||||
) {
|
||||
self.refinedTemplates = refinedTemplates
|
||||
self.atmosphereTemplates = atmosphereTemplates
|
||||
self.coverTemplates = coverTemplates
|
||||
}
|
||||
}
|
||||
|
||||
/// 提交 AI 修图任务的请求参数。
|
||||
struct TravelAlbumAIRetouchRequest: Encodable, Sendable, Equatable {
|
||||
let userEquityTravelId: Int
|
||||
let materialIds: [Int]
|
||||
let refinedTemplateId: Int
|
||||
let atmosphereTemplateId: Int?
|
||||
let aiPreviewTabs: Int?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case userEquityTravelId = "user_equity_travel_id"
|
||||
case materialIds = "material_ids"
|
||||
case refinedTemplateId = "refined_template_id"
|
||||
case atmosphereTemplateId = "atmosphere_template_id"
|
||||
case aiPreviewTabs = "ai_preview_tabs"
|
||||
}
|
||||
}
|
||||
|
||||
/// 旅拍相册展示格式化工具。
|
||||
enum TravelAlbumDisplayFormatter {
|
||||
/// 脱敏手机号。
|
||||
|
||||
@@ -84,10 +84,10 @@ struct TravelAlbumPreviewProject: Identifiable, Sendable, Hashable {
|
||||
assets.first { $0.kind == kind }
|
||||
}
|
||||
|
||||
/// 将当前素材映射为仅含原图的预览项目;新接口接入后替换此适配层即可。
|
||||
/// 将素材映射为原图及实际存在的 AI 精修、氛围感结果图。
|
||||
init(material: TravelAlbumMaterial) {
|
||||
originalMaterialId = material.id
|
||||
assets = [
|
||||
var mappedAssets = [
|
||||
TravelAlbumPreviewAsset(
|
||||
id: "original-\(material.id)",
|
||||
kind: .original,
|
||||
@@ -97,6 +97,33 @@ struct TravelAlbumPreviewProject: Identifiable, Sendable, Hashable {
|
||||
fileSize: material.fileSize
|
||||
),
|
||||
]
|
||||
let refinedURL = material.aiRefinedURL.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
if !refinedURL.isEmpty {
|
||||
mappedAssets.append(
|
||||
TravelAlbumPreviewAsset(
|
||||
id: "retouched-\(material.id)",
|
||||
kind: .retouched,
|
||||
fileURL: refinedURL,
|
||||
coverURL: refinedURL,
|
||||
fileName: material.fileName,
|
||||
fileSize: material.fileSize
|
||||
)
|
||||
)
|
||||
}
|
||||
let atmosphereURL = material.aiAtmosphereURL.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
if !atmosphereURL.isEmpty {
|
||||
mappedAssets.append(
|
||||
TravelAlbumPreviewAsset(
|
||||
id: "atmosphere-\(material.id)",
|
||||
kind: .atmosphere,
|
||||
fileURL: atmosphereURL,
|
||||
coverURL: atmosphereURL,
|
||||
fileName: material.fileName,
|
||||
fileSize: material.fileSize
|
||||
)
|
||||
)
|
||||
}
|
||||
assets = mappedAssets
|
||||
}
|
||||
|
||||
/// 创建包含关联图片的项目,主要供适配器和测试使用。
|
||||
@@ -142,6 +169,15 @@ enum TravelAlbumPreviewNavigator {
|
||||
$0.projectIndex == current.projectIndex - 1 && $0.kind == .original
|
||||
} ?? currentIndex - 1
|
||||
}
|
||||
|
||||
/// 返回删除当前项目后应展示的项目索引;优先保持原索引以显示下一张,末项则回退上一张。
|
||||
static func projectIndexAfterDeletion(
|
||||
deletedProjectIndex: Int,
|
||||
remainingProjectCount: Int
|
||||
) -> Int? {
|
||||
guard remainingProjectCount > 0 else { return nil }
|
||||
return min(max(0, deletedProjectIndex), remainingProjectCount - 1)
|
||||
}
|
||||
}
|
||||
|
||||
/// 预览操作执行结果,便于后续替换真实业务接口。
|
||||
|
||||
Reference in New Issue
Block a user