87 lines
2.9 KiB
Dart
87 lines
2.9 KiB
Dart
/// 媒体项: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<GalleryMediaItem> mediaItems;
|
||
|
||
factory GalleryTaskItem.fromJson(Map<String, dynamic> json) {
|
||
final downsample = json['downsample'] as List<dynamic>? ?? [];
|
||
final items = <GalleryMediaItem>[];
|
||
// 只取downsample的array[0]
|
||
if (downsample.isNotEmpty) {
|
||
final first = downsample[0];
|
||
if (first is String) {
|
||
items.add(GalleryMediaItem(imageUrl: first));
|
||
} else if (first is Map<String, dynamic>) {
|
||
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));
|
||
} else {
|
||
items.add(GalleryMediaItem(imageUrl: reconfigure));
|
||
}
|
||
}
|
||
}
|
||
// 后续下标均忽略
|
||
}
|
||
// for (final item in downsample) {
|
||
// if (item is String) {
|
||
// items.add(GalleryMediaItem(imageUrl: item));
|
||
// } else if (item is Map<String, dynamic>) {
|
||
// 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,
|
||
);
|
||
}
|
||
}
|