mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-06 05:49:03 +08:00
Add support for import gallery
This commit is contained in:
@@ -12,7 +12,9 @@ enum TaskType {
|
|||||||
@JsonValue(2)
|
@JsonValue(2)
|
||||||
updateMeiliSearchData,
|
updateMeiliSearchData,
|
||||||
@JsonValue(3)
|
@JsonValue(3)
|
||||||
fixGalleryPage;
|
fixGalleryPage,
|
||||||
|
@JsonValue(4)
|
||||||
|
import;
|
||||||
|
|
||||||
String text(BuildContext context) {
|
String text(BuildContext context) {
|
||||||
final i18n = AppLocalizations.of(context)!;
|
final i18n = AppLocalizations.of(context)!;
|
||||||
@@ -25,6 +27,8 @@ enum TaskType {
|
|||||||
return i18n.updateMeiliSearchDataTask;
|
return i18n.updateMeiliSearchDataTask;
|
||||||
case TaskType.fixGalleryPage:
|
case TaskType.fixGalleryPage:
|
||||||
return i18n.fixGalleryPageTask;
|
return i18n.fixGalleryPageTask;
|
||||||
|
case TaskType.import:
|
||||||
|
return i18n.importTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,6 +164,24 @@ class TaskFixGalleryPageProgress implements TaskProgressBasicType {
|
|||||||
Map<String, dynamic> toJson() => _$TaskFixGalleryPageProgressToJson(this);
|
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 {
|
class TaskProgress {
|
||||||
const TaskProgress({
|
const TaskProgress({
|
||||||
required this.type,
|
required this.type,
|
||||||
@@ -201,6 +223,13 @@ class TaskProgress {
|
|||||||
detail: TaskFixGalleryPageProgress.fromJson(
|
detail: TaskFixGalleryPageProgress.fromJson(
|
||||||
json['detail'] as Map<String, dynamic>),
|
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:
|
default:
|
||||||
throw ArgumentError.value(type, 'type', 'Invalid task type');
|
throw ArgumentError.value(type, 'type', 'Invalid task type');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const _$TaskTypeEnumMap = {
|
|||||||
TaskType.exportZip: 1,
|
TaskType.exportZip: 1,
|
||||||
TaskType.updateMeiliSearchData: 2,
|
TaskType.updateMeiliSearchData: 2,
|
||||||
TaskType.fixGalleryPage: 3,
|
TaskType.fixGalleryPage: 3,
|
||||||
|
TaskType.import: 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
TaskDownloadSingleProgress _$TaskDownloadSingleProgressFromJson(
|
TaskDownloadSingleProgress _$TaskDownloadSingleProgressFromJson(
|
||||||
@@ -131,6 +132,20 @@ Map<String, dynamic> _$TaskFixGalleryPageProgressToJson(
|
|||||||
'checked_gallery': instance.checkedGallery,
|
'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(
|
TaskList _$TaskListFromJson(Map<String, dynamic> json) => TaskList(
|
||||||
tasks: (json['tasks'] as List<dynamic>)
|
tasks: (json['tasks'] as List<dynamic>)
|
||||||
.map((e) => Task.fromJson(e as Map<String, dynamic>))
|
.map((e) => Task.fromJson(e as Map<String, dynamic>))
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ class _TaskView extends State<TaskView> {
|
|||||||
final progress =
|
final progress =
|
||||||
widget.task.progress as TaskUpdateMeiliSearchDataProgress;
|
widget.task.progress as TaskUpdateMeiliSearchDataProgress;
|
||||||
return progress.updatedGallery / progress.totalGallery;
|
return progress.updatedGallery / progress.totalGallery;
|
||||||
|
case TaskType.import:
|
||||||
|
final progress = widget.task.progress as TaskImportProgress;
|
||||||
|
return progress.importedPage / progress.totalPage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -240,6 +240,10 @@ class _TaskPage extends State<TaskPage> {
|
|||||||
final p = task.progress as TaskUpdateMeiliSearchDataProgress;
|
final p = task.progress as TaskUpdateMeiliSearchDataProgress;
|
||||||
now = p.updatedGallery;
|
now = p.updatedGallery;
|
||||||
total = p.totalGallery;
|
total = p.totalGallery;
|
||||||
|
case TaskType.import:
|
||||||
|
final p = task.progress as TaskImportProgress;
|
||||||
|
now = p.importedPage;
|
||||||
|
total = p.totalPage;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
if (total == 0) return Container();
|
if (total == 0) return Container();
|
||||||
@@ -332,7 +336,8 @@ class _TaskPage extends State<TaskPage> {
|
|||||||
bool get haveMetaInfo {
|
bool get haveMetaInfo {
|
||||||
if (!tasks.tasksList.contains(widget.id)) return false;
|
if (!tasks.tasksList.contains(widget.id)) return false;
|
||||||
final task = tasks.tasks[widget.id]!;
|
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);
|
tasks.meta.containsKey(task.base.gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -243,5 +243,6 @@
|
|||||||
"failedLogout": "Failed to log out: ",
|
"failedLogout": "Failed to log out: ",
|
||||||
"createExportZipTask": "Create export as ZIP file task",
|
"createExportZipTask": "Create export as ZIP file task",
|
||||||
"outputDir": "Output directory",
|
"outputDir": "Output directory",
|
||||||
"copyOriImgUrl": "Copy original image URL to clipboard"
|
"copyOriImgUrl": "Copy original image URL to clipboard",
|
||||||
|
"importTask": "Import task"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,5 +243,6 @@
|
|||||||
"failedLogout": "退出登录失败:",
|
"failedLogout": "退出登录失败:",
|
||||||
"createExportZipTask": "新建导出为ZIP文件任务",
|
"createExportZipTask": "新建导出为ZIP文件任务",
|
||||||
"outputDir": "输出文件夹",
|
"outputDir": "输出文件夹",
|
||||||
"copyOriImgUrl": "复制原图链接到剪贴板"
|
"copyOriImgUrl": "复制原图链接到剪贴板",
|
||||||
|
"importTask": "导入任务"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,8 @@ class TaskManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void addToTasksList(Task task, TaskStatus status) {
|
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)) {
|
if (peddingGids.contains(task.gid)) {
|
||||||
final index = peddingGids.indexOf(task.gid);
|
final index = peddingGids.indexOf(task.gid);
|
||||||
if (peddingTokens[index]! != task.token) {
|
if (peddingTokens[index]! != task.token) {
|
||||||
|
|||||||
Reference in New Issue
Block a user