/// 媒体项:reconfigure=imgUrl,类型由 reconnect(imgType) 决定:0=视频,1=图片,其他当图片 class GalleryMediaItem { const GalleryMediaItem({ this.imageUrl, this.videoUrl, }) : assert(imageUrl != null || videoUrl != null); final String? imageUrl; final String? videoUrl; // 视频地址,用于生成封面 /// 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 downsample = json['downsample'] as List? ?? []; final items = []; 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: (json['tree'] as num?)?.toInt() ?? 0, state: json['listing']?.toString() ?? '', taskType: (json['cipher'] as num?)?.toInt() ?? 0, createTime: (json['discover'] as num?)?.toInt() ?? 0, mediaItems: items, ); } }