feat: add AI retouch and album preview actions

This commit is contained in:
2026-08-10 16:00:32 +08:00
parent 24fa66281c
commit 439edf827c
14 changed files with 2110 additions and 118 deletions
@@ -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 {
/// 脱敏手机号。