修复样片详情解析并优化列表上下架交互。

兼容 Android 媒体项 size 字段格式,增强灵活解码容错,并统一样片列表开关确认逻辑与安全区布局。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-13 15:14:40 +08:00
parent afcd412f11
commit 07b2b9d459
7 changed files with 96 additions and 47 deletions

View File

@ -329,6 +329,31 @@ struct SampleDetailMediaItem: Decodable, Sendable, Equatable, Hashable, Identifi
case height
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decodeIfPresent(Int.self, forKey: .id) ?? 0
originalName = try container.decodeIfPresent(String.self, forKey: .originalName)
paidMaterialId = try container.decodeIfPresent(Int.self, forKey: .paidMaterialId)
ossUrl = try container.decodeIfPresent(String.self, forKey: .ossUrl)
thumbnailUrl = try container.decodeIfPresent(String.self, forKey: .thumbnailUrl)
type = try container.decodeIfPresent(Int.self, forKey: .type) ?? 0
if let numericSize = try? container.decode(Int64.self, forKey: .size) {
size = numericSize
} else if let stringSize = try? container.decode(String.self, forKey: .size) {
size = Int64(stringSize)
} else {
size = nil
}
createdAt = try container.decodeIfPresent(String.self, forKey: .createdAt)
updatedAt = try container.decodeIfPresent(String.self, forKey: .updatedAt)
deletedAt = try container.decodeIfPresent(String.self, forKey: .deletedAt)
likesCount = try container.decodeIfPresent(Int.self, forKey: .likesCount) ?? 0
downloadCount = try container.decodeIfPresent(Int.self, forKey: .downloadCount) ?? 0
showUrl = try container.decodeIfPresent(String.self, forKey: .showUrl)
width = try container.decodeIfPresent(Int.self, forKey: .width)
height = try container.decodeIfPresent(Int.self, forKey: .height)
}
///
var displayURL: String {
(ossUrl?.trimmingCharacters(in: .whitespacesAndNewlines).nonEmpty)
@ -558,23 +583,23 @@ enum SampleDisplayFormatter {
private extension KeyedDecodingContainer {
func decodeFlexibleDouble(forKey key: Key) throws -> Double? {
if let value = try decodeIfPresent(Double.self, forKey: key) {
if let value = try? decode(Double.self, forKey: key) {
return value
}
if let string = try decodeIfPresent(String.self, forKey: key) {
if let string = try? decode(String.self, forKey: key) {
return Double(string)
}
return nil
}
func decodeFlexibleString(forKey key: Key) throws -> String? {
if let value = try decodeIfPresent(String.self, forKey: key) {
if let value = try? decode(String.self, forKey: key) {
return value
}
if let value = try decodeIfPresent(Double.self, forKey: key) {
if let value = try? decode(Double.self, forKey: key) {
return String(value)
}
if let value = try decodeIfPresent(Int.self, forKey: key) {
if let value = try? decode(Int.self, forKey: key) {
return String(value)
}
return nil

View File

@ -503,6 +503,7 @@ final class UploadSampleViewModel {
guard let self else { return }
Task { @MainActor in
guard self.uploadedMediaList.indices.contains(index) else { return }
guard self.uploadedMediaList[index].isUploading else { return }
self.uploadedMediaList[index].uploadProgress = progress
self.uploadedMediaList[index].isUploading = progress < 100
self.uploadDialogState = SampleUploadDialogState(
@ -552,6 +553,7 @@ final class UploadSampleViewModel {
guard let self else { return }
Task { @MainActor in
guard var current = self.coverImage else { return }
guard current.isUploading else { return }
current.uploadProgress = progress
current.isUploading = progress < 100
self.coverImage = current