mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-25 21:26:50 +08:00
Add import task
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -1460,6 +1460,61 @@ class __EHApi implements _EHApi {
|
||||
return value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ApiResult<Task>> createImportTask(
|
||||
int gid,
|
||||
String token, {
|
||||
ImportConfig? cfg,
|
||||
String t = "import",
|
||||
CancelToken? cancel,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
queryParameters.removeWhere((k, v) => v == null);
|
||||
final _headers = <String, dynamic>{};
|
||||
final _data = FormData();
|
||||
_data.fields.add(MapEntry(
|
||||
'gid',
|
||||
gid.toString(),
|
||||
));
|
||||
_data.fields.add(MapEntry(
|
||||
'token',
|
||||
token,
|
||||
));
|
||||
_data.fields.add(MapEntry(
|
||||
'cfg',
|
||||
jsonEncode(cfg ?? <String, dynamic>{}),
|
||||
));
|
||||
_data.fields.add(MapEntry(
|
||||
'type',
|
||||
t,
|
||||
));
|
||||
final _result = await _dio
|
||||
.fetch<Map<String, dynamic>>(_setStreamType<ApiResult<Task>>(Options(
|
||||
method: 'PUT',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
contentType: 'multipart/form-data',
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/task',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
cancelToken: cancel,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final value = ApiResult<Task>.fromJson(
|
||||
_result.data!,
|
||||
(json) => Task.fromJson(json as Map<String, dynamic>),
|
||||
);
|
||||
return value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ApiResult<DownloadConfig>> getDefaultDownloadConfig(
|
||||
{CancelToken? cancel}) async {
|
||||
@@ -1526,6 +1581,39 @@ class __EHApi implements _EHApi {
|
||||
return value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ApiResult<DefaultImportConfig>> getDefaultImportConfig(
|
||||
{CancelToken? cancel}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
queryParameters.removeWhere((k, v) => v == null);
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(
|
||||
_setStreamType<ApiResult<DefaultImportConfig>>(Options(
|
||||
method: 'GET',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/task/import_cfg',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
cancelToken: cancel,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final value = ApiResult<DefaultImportConfig>.fromJson(
|
||||
_result.data!,
|
||||
(json) => DefaultImportConfig.fromJson(json as Map<String, dynamic>),
|
||||
);
|
||||
return value;
|
||||
}
|
||||
|
||||
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
|
||||
if (T != dynamic &&
|
||||
!(requestOptions.responseType == ResponseType.bytes ||
|
||||
|
||||
@@ -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')
|
||||
@@ -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);
|
||||
|
||||
@@ -28,6 +28,8 @@ ServerStatus _$ServerStatusFromJson(Map<String, dynamic> json) => ServerStatus(
|
||||
json['meilisearch'] as Map<String, dynamic>),
|
||||
noUser: json['no_user'] as bool,
|
||||
isDocker: json['is_docker'] as bool,
|
||||
ffprobeBinaryEnabled: json['ffprobe_binary_enabled'] as bool,
|
||||
libzipEnabled: json['libzip_enabled'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ServerStatusToJson(ServerStatus instance) =>
|
||||
@@ -38,4 +40,6 @@ Map<String, dynamic> _$ServerStatusToJson(ServerStatus instance) =>
|
||||
'meilisearch': instance.meilisearch,
|
||||
'no_user': instance.noUser,
|
||||
'is_docker': instance.isDocker,
|
||||
'ffprobe_binary_enabled': instance.ffprobeBinaryEnabled,
|
||||
'libzip_enabled': instance.libzipEnabled,
|
||||
};
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -205,3 +205,56 @@ Map<String, dynamic> _$ExportZipConfigToJson(ExportZipConfig instance) =>
|
||||
'max_length': instance.maxLength,
|
||||
'export_ad': instance.exportAd,
|
||||
};
|
||||
|
||||
ImportConfig _$ImportConfigFromJson(Map<String, dynamic> json) => ImportConfig(
|
||||
json['import_path'] as String,
|
||||
size: $enumDecodeNullable(_$ImportSizeEnumMap, json['size']) ??
|
||||
ImportSize.original,
|
||||
maxImportImgCount: (json['max_import_img_count'] as num?)?.toInt(),
|
||||
mpv: json['mpv'] as bool?,
|
||||
method: $enumDecodeNullable(_$ImportMethodEnumMap, json['method']),
|
||||
removePreviousGallery: json['remove_previous_gallery'] as bool?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ImportConfigToJson(ImportConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'max_import_img_count': instance.maxImportImgCount,
|
||||
'mpv': instance.mpv,
|
||||
'method': _$ImportMethodEnumMap[instance.method],
|
||||
'remove_previous_gallery': instance.removePreviousGallery,
|
||||
'import_path': instance.importPath,
|
||||
'size': _$ImportSizeEnumMap[instance.size]!,
|
||||
};
|
||||
|
||||
const _$ImportSizeEnumMap = {
|
||||
ImportSize.original: 0,
|
||||
ImportSize.x780: 780,
|
||||
ImportSize.x980: 980,
|
||||
ImportSize.resampled: 1280,
|
||||
ImportSize.x1600: 1600,
|
||||
ImportSize.x2400: 2400,
|
||||
};
|
||||
|
||||
const _$ImportMethodEnumMap = {
|
||||
ImportMethod.copy: 0,
|
||||
ImportMethod.copyThenDelete: 1,
|
||||
ImportMethod.move: 2,
|
||||
ImportMethod.keep: 3,
|
||||
};
|
||||
|
||||
DefaultImportConfig _$DefaultImportConfigFromJson(Map<String, dynamic> json) =>
|
||||
DefaultImportConfig(
|
||||
maxImportImgCount: (json['max_import_img_count'] as num?)?.toInt(),
|
||||
method: $enumDecodeNullable(_$ImportMethodEnumMap, json['method']),
|
||||
mpv: json['mpv'] as bool?,
|
||||
removePreviousGallery: json['remove_previous_gallery'] as bool?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$DefaultImportConfigToJson(
|
||||
DefaultImportConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'max_import_img_count': instance.maxImportImgCount,
|
||||
'method': _$ImportMethodEnumMap[instance.method],
|
||||
'mpv': instance.mpv,
|
||||
'remove_previous_gallery': instance.removePreviousGallery,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user