/// 媒体项:reconfigure=imgUrl,类型由 reconnect(imgType) 决定:0=视频,1=图片,其他当图片 class GalleryMediaItem { const GalleryMediaItem({ this.imageUrl, this.videoUrl, this.taskId, }) : assert(imageUrl != null || videoUrl != null); final String? imageUrl; final String? videoUrl; /// 与列表项 `tree` 一致,用于匹配本地上传封面缓存 final int? taskId; /// reconnect==0 为视频,1 或其他为图片 bool get isVideo => videoUrl != null && (imageUrl == null || imageUrl!.isEmpty); } /// 我的任务项(V2 字段映射) class GalleryTaskItem { const GalleryTaskItem({ required this.taskId, required this.state, required this.taskType, required this.createTime, required this.mediaItems, }); final int taskId; final String state; final int taskType; final int createTime; final List mediaItems; factory GalleryTaskItem.fromJson(Map json) { final treeRaw = json['tree'] as num?; final treeId = treeRaw?.toInt() ?? 0; final itemTaskId = treeId > 0 ? treeId : null; final downsample = json['downsample'] as List? ?? []; final items = []; // 只取downsample的array[0] if (downsample.isNotEmpty) { final first = downsample[0]; if (first is String) { items.add(GalleryMediaItem(imageUrl: first, taskId: itemTaskId)); } else if (first is Map) { final reconfigure = first['reconfigure'] as String?; if (reconfigure != null && reconfigure.isNotEmpty) { final reconnect = first['reconnect']; final imgType = reconnect is int ? reconnect : reconnect is num ? reconnect.toInt() : 1; if (imgType == 2) { items.add(GalleryMediaItem( videoUrl: reconfigure, taskId: itemTaskId, )); } else { items.add(GalleryMediaItem( imageUrl: reconfigure, taskId: itemTaskId, )); } } } // 后续下标均忽略 } // for (final item in downsample) { // if (item is String) { // items.add(GalleryMediaItem(imageUrl: item)); // } else if (item is Map) { // final reconfigure = item['reconfigure'] as String?; // if (reconfigure == null || reconfigure.isEmpty) continue; // // reconnect(imgType): 0=视频,1=图片,其他默认当图片 // final reconnect = item['reconnect']; // final imgType = reconnect is int // ? reconnect // : reconnect is num // ? reconnect.toInt() // : 1; // if (imgType == 2) { // items.add(GalleryMediaItem(videoUrl: reconfigure)); // } else { // items.add(GalleryMediaItem(imageUrl: reconfigure)); // } // } // } return GalleryTaskItem( taskId: treeId, state: json['listing']?.toString() ?? '', taskType: (json['cipher'] as num?)?.toInt() ?? 0, createTime: (json['discover'] as num?)?.toInt() ?? 0, mediaItems: items, ); } }