新增资产模块,包含云存储与媒体库流程
为云端与素材管理页面接入首页路由,将共享云存储模型迁入 Assets 模块,并补充 API/ViewModel 测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -283,76 +283,6 @@ struct UploadFileItem: Encodable, Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
/// 云盘文件实体,表示发布任务时可选择的云盘文件或文件夹。
|
||||
struct CloudDriveFile: Decodable, Identifiable, Hashable {
|
||||
let id: Int
|
||||
let parentFolderId: Int
|
||||
let fileUrl: String
|
||||
let coverUrl: String
|
||||
let updatedAt: String
|
||||
let name: String
|
||||
let createdAt: String
|
||||
let childNum: Int
|
||||
let type: Int
|
||||
let fileSize: Int64
|
||||
|
||||
/// 判断当前云盘项是否为文件夹。
|
||||
var isFolder: Bool { type == 99 }
|
||||
|
||||
/// 判断当前云盘项是否为视频文件。
|
||||
var isVideo: Bool {
|
||||
type == 1 || Self.hasVideoExtension(name) || Self.hasVideoExtension(fileUrl)
|
||||
}
|
||||
|
||||
/// 根据文件扩展名判断是否是常见视频格式。
|
||||
private static func hasVideoExtension(_ value: String) -> Bool {
|
||||
["mp4", "mov", "m4v", "avi"].contains(URL(string: value)?.pathExtension.lowercased() ?? URL(fileURLWithPath: value).pathExtension.lowercased())
|
||||
}
|
||||
|
||||
/// 云盘文件字段映射,兼容后端下划线命名。
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case parentFolderId = "parent_folder_id"
|
||||
case fileUrl = "file_url"
|
||||
case coverUrl = "cover_url"
|
||||
case updatedAt = "updated_at"
|
||||
case name
|
||||
case createdAt = "created_at"
|
||||
case childNum = "child_num"
|
||||
case type
|
||||
case fileSize = "file_size"
|
||||
}
|
||||
|
||||
/// 构造本地路径根节点,供云盘选择器维护面包屑。
|
||||
init(id: Int, name: String) {
|
||||
self.id = id
|
||||
parentFolderId = 0
|
||||
fileUrl = ""
|
||||
coverUrl = ""
|
||||
updatedAt = ""
|
||||
self.name = name
|
||||
createdAt = ""
|
||||
childNum = 0
|
||||
type = 99
|
||||
fileSize = 0
|
||||
}
|
||||
|
||||
/// 宽松解码云盘文件字段。
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = try container.decodeLossyInt(forKey: .id) ?? 0
|
||||
parentFolderId = try container.decodeLossyInt(forKey: .parentFolderId) ?? 0
|
||||
fileUrl = try container.decodeLossyString(forKey: .fileUrl)
|
||||
coverUrl = try container.decodeLossyString(forKey: .coverUrl)
|
||||
updatedAt = try container.decodeLossyString(forKey: .updatedAt)
|
||||
name = try container.decodeLossyString(forKey: .name)
|
||||
createdAt = try container.decodeLossyString(forKey: .createdAt)
|
||||
childNum = try container.decodeLossyInt(forKey: .childNum) ?? 0
|
||||
type = try container.decodeLossyInt(forKey: .type) ?? 0
|
||||
fileSize = Int64(try container.decodeLossyInt(forKey: .fileSize) ?? 0)
|
||||
}
|
||||
}
|
||||
|
||||
private extension KeyedDecodingContainer {
|
||||
/// 将 String、数字和 Bool 宽松解码为字符串。
|
||||
func decodeLossyString(forKey key: Key) throws -> String {
|
||||
|
||||
Reference in New Issue
Block a user