petsHero-AI/lib/features/gallery/models/gallery_task_item.dart

56 lines
1.8 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/// 媒体项digitize=图片URLreconfigure=视频URL需生成封面
class GalleryMediaItem {
const GalleryMediaItem({
this.imageUrl,
this.videoUrl,
}) : assert(imageUrl != null || videoUrl != null);
final String? imageUrl; // digitize
final String? videoUrl; // reconfigure - 视频地址,用于生成封面
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>[];
for (final item in downsample) {
if (item is String) {
items.add(GalleryMediaItem(imageUrl: item));
} else if (item is Map<String, dynamic>) {
final digitize = item['digitize'] as String?;
final reconfigure = item['reconfigure'] as String?;
// digitize=图片, reconfigure=视频;优先用图片,否则用视频生成封面
if (digitize != null && digitize.isNotEmpty) {
items.add(GalleryMediaItem(imageUrl: digitize));
} else if (reconfigure != null && reconfigure.isNotEmpty) {
items.add(GalleryMediaItem(videoUrl: 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,
);
}
}