Add support for import gallery

This commit is contained in:
2024-06-07 13:56:12 +00:00
committed by GitHub
parent 83753b666e
commit 896dca9516
7 changed files with 60 additions and 5 deletions

View File

@@ -12,7 +12,9 @@ enum TaskType {
@JsonValue(2)
updateMeiliSearchData,
@JsonValue(3)
fixGalleryPage;
fixGalleryPage,
@JsonValue(4)
import;
String text(BuildContext context) {
final i18n = AppLocalizations.of(context)!;
@@ -25,6 +27,8 @@ enum TaskType {
return i18n.updateMeiliSearchDataTask;
case TaskType.fixGalleryPage:
return i18n.fixGalleryPageTask;
case TaskType.import:
return i18n.importTask;
}
}
}
@@ -160,6 +164,24 @@ class TaskFixGalleryPageProgress implements TaskProgressBasicType {
Map<String, dynamic> toJson() => _$TaskFixGalleryPageProgressToJson(this);
}
@JsonSerializable()
class TaskImportProgress implements TaskProgressBasicType {
const TaskImportProgress({
required this.importedPage,
required this.failedPage,
required this.totalPage,
});
@JsonKey(name: 'imported_page')
final int importedPage;
@JsonKey(name: 'failed_page')
final int failedPage;
@JsonKey(name: 'total_page')
final int totalPage;
factory TaskImportProgress.fromJson(Map<String, dynamic> json) =>
_$TaskImportProgressFromJson(json);
Map<String, dynamic> toJson() => _$TaskImportProgressToJson(this);
}
class TaskProgress {
const TaskProgress({
required this.type,
@@ -201,6 +223,13 @@ class TaskProgress {
detail: TaskFixGalleryPageProgress.fromJson(
json['detail'] as Map<String, dynamic>),
);
case 4:
return TaskProgress(
type: TaskType.import,
taskId: taskId,
detail: TaskImportProgress.fromJson(
json['detail'] as Map<String, dynamic>),
);
default:
throw ArgumentError.value(type, 'type', 'Invalid task type');
}

View File

@@ -29,6 +29,7 @@ const _$TaskTypeEnumMap = {
TaskType.exportZip: 1,
TaskType.updateMeiliSearchData: 2,
TaskType.fixGalleryPage: 3,
TaskType.import: 4,
};
TaskDownloadSingleProgress _$TaskDownloadSingleProgressFromJson(
@@ -131,6 +132,20 @@ Map<String, dynamic> _$TaskFixGalleryPageProgressToJson(
'checked_gallery': instance.checkedGallery,
};
TaskImportProgress _$TaskImportProgressFromJson(Map<String, dynamic> json) =>
TaskImportProgress(
importedPage: (json['imported_page'] as num).toInt(),
failedPage: (json['failed_page'] as num).toInt(),
totalPage: (json['total_page'] as num).toInt(),
);
Map<String, dynamic> _$TaskImportProgressToJson(TaskImportProgress instance) =>
<String, dynamic>{
'imported_page': instance.importedPage,
'failed_page': instance.failedPage,
'total_page': instance.totalPage,
};
TaskList _$TaskListFromJson(Map<String, dynamic> json) => TaskList(
tasks: (json['tasks'] as List<dynamic>)
.map((e) => Task.fromJson(e as Map<String, dynamic>))