Skip to content

Commit

Permalink
Add import task
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc authored Aug 10, 2024
1 parent 92646cf commit 79e1ca9
Show file tree
Hide file tree
Showing 17 changed files with 793 additions and 141 deletions.
12 changes: 12 additions & 0 deletions lib/api/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,24 @@ abstract class _EHApi {
{@Part(name: 'cfg') ExportZipConfig? cfg,
@Part(name: "type") String t = "export_zip",
@CancelRequest() CancelToken? cancel});
@PUT('/task')
@MultiPart()
Future<ApiResult<Task>> createImportTask(
@Part(name: "gid") int gid,
@Part(name: "token") String token, {
@Part(name: "cfg") ImportConfig? cfg,
@Part(name: "type") String t = "import",
@CancelRequest() CancelToken? cancel,
});
@GET('/task/download_cfg')
Future<ApiResult<DownloadConfig>> getDefaultDownloadConfig(
{@CancelRequest() CancelToken? cancel});
@GET('/task/export_zip_cfg')
Future<ApiResult<ExportZipConfig>> getDefaultExportZipConfig(
{@CancelRequest() CancelToken? cancel});
@GET('/task/import_cfg')
Future<ApiResult<DefaultImportConfig>> getDefaultImportConfig(
{@CancelRequest() CancelToken? cancel});
}

class EHApi extends __EHApi {
Expand Down
88 changes: 88 additions & 0 deletions lib/api/client.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/api/status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class ServerStatus {
this.meilisearch,
required this.noUser,
required this.isDocker,
required this.ffprobeBinaryEnabled,
required this.libzipEnabled,
});

@JsonKey(name: 'ffmpeg_api_enabled')
Expand All @@ -40,6 +42,10 @@ class ServerStatus {
final bool noUser;
@JsonKey(name: 'is_docker')
final bool isDocker;
@JsonKey(name: 'ffprobe_binary_enabled')
final bool ffprobeBinaryEnabled;
@JsonKey(name: 'libzip_enabled')
final bool libzipEnabled;

factory ServerStatus.fromJson(Map<String, dynamic> json) =>
_$ServerStatusFromJson(json);
Expand Down
4 changes: 4 additions & 0 deletions lib/api/status.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions lib/api/task.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:json_annotation/json_annotation.dart';
import 'config.dart';

part 'task.g.dart';

Expand Down Expand Up @@ -346,3 +347,61 @@ class ExportZipConfig {
_$ExportZipConfigFromJson(json);
Map<String, dynamic> toJson() => _$ExportZipConfigToJson(this);
}

enum ImportSize {
@JsonValue(0)
original,
@JsonValue(780)
x780,
@JsonValue(980)
x980,
@JsonValue(1280)
resampled,
@JsonValue(1600)
x1600,
@JsonValue(2400)
x2400,
}

@JsonSerializable()
class ImportConfig {
ImportConfig(
this.importPath, {
this.size = ImportSize.original,
this.maxImportImgCount,
this.mpv,
this.method,
this.removePreviousGallery,
});
@JsonKey(name: 'max_import_img_count')
int? maxImportImgCount;
bool? mpv;
ImportMethod? method;
@JsonKey(name: 'remove_previous_gallery')
bool? removePreviousGallery;
@JsonKey(name: 'import_path')
String importPath;
ImportSize size;
factory ImportConfig.fromJson(Map<String, dynamic> json) =>
_$ImportConfigFromJson(json);
Map<String, dynamic> toJson() => _$ImportConfigToJson(this);
}

@JsonSerializable()
class DefaultImportConfig {
DefaultImportConfig({
this.maxImportImgCount,
this.method,
this.mpv,
this.removePreviousGallery,
});
@JsonKey(name: 'max_import_img_count')
int? maxImportImgCount;
ImportMethod? method;
bool? mpv;
@JsonKey(name: 'remove_previous_gallery')
bool? removePreviousGallery;
factory DefaultImportConfig.fromJson(Map<String, dynamic> json) =>
_$DefaultImportConfigFromJson(json);
Map<String, dynamic> toJson() => _$DefaultImportConfigToJson(this);
}
53 changes: 53 additions & 0 deletions lib/api/task.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lib/components/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ class _TaskView extends State<TaskView> {
return Text("${i18n.exportZipTask} $title",
maxLines: 1, overflow: TextOverflow.ellipsis);
}
if (typ == TaskType.import) {
final gid = widget.task.base.gid;
final title = tasks.meta.containsKey(gid)
? tasks.meta[gid]!.preferredTitle
: gid.toString();
return Text("${i18n.importTask} $title",
maxLines: 1, overflow: TextOverflow.ellipsis);
}
return Container();
}

Expand Down
1 change: 0 additions & 1 deletion lib/dialog/new_export_zip_task_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:logging/logging.dart';
import '../api/gallery.dart';
import '../components/labeled_checkbox.dart';
import '../components/number_field.dart';
import '../globals.dart';
Expand Down
Loading

0 comments on commit 79e1ca9

Please sign in to comment.