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>))

View File

@@ -54,6 +54,9 @@ class _TaskView extends State<TaskView> {
final progress =
widget.task.progress as TaskUpdateMeiliSearchDataProgress;
return progress.updatedGallery / progress.totalGallery;
case TaskType.import:
final progress = widget.task.progress as TaskImportProgress;
return progress.importedPage / progress.totalPage;
}
}

View File

@@ -240,6 +240,10 @@ class _TaskPage extends State<TaskPage> {
final p = task.progress as TaskUpdateMeiliSearchDataProgress;
now = p.updatedGallery;
total = p.totalGallery;
case TaskType.import:
final p = task.progress as TaskImportProgress;
now = p.importedPage;
total = p.totalPage;
default:
}
if (total == 0) return Container();
@@ -332,7 +336,8 @@ class _TaskPage extends State<TaskPage> {
bool get haveMetaInfo {
if (!tasks.tasksList.contains(widget.id)) return false;
final task = tasks.tasks[widget.id]!;
return task.base.type == TaskType.download &&
final typ = task.base.type;
return (typ == TaskType.download || typ == TaskType.import) &&
tasks.meta.containsKey(task.base.gid);
}

View File

@@ -243,5 +243,6 @@
"failedLogout": "Failed to log out: ",
"createExportZipTask": "Create export as ZIP file task",
"outputDir": "Output directory",
"copyOriImgUrl": "Copy original image URL to clipboard"
"copyOriImgUrl": "Copy original image URL to clipboard",
"importTask": "Import task"
}

View File

@@ -243,5 +243,6 @@
"failedLogout": "退出登录失败:",
"createExportZipTask": "新建导出为ZIP文件任务",
"outputDir": "输出文件夹",
"copyOriImgUrl": "复制原图链接到剪贴板"
"copyOriImgUrl": "复制原图链接到剪贴板",
"importTask": "导入任务"
}

View File

@@ -89,7 +89,8 @@ class TaskManager {
}
void addToTasksList(Task task, TaskStatus status) {
if (task.type == TaskType.download && !meta.containsKey(task.gid)) {
if ((task.type == TaskType.download || task.type == TaskType.import) &&
!meta.containsKey(task.gid)) {
if (peddingGids.contains(task.gid)) {
final index = peddingGids.indexOf(task.gid);
if (peddingTokens[index]! != task.token) {