mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-04 08:02:25 +08:00
Add server settings page
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:eh_downloader_flutter/api/file.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
|
||||
import 'api_result.dart';
|
||||
import 'config.dart';
|
||||
import 'gallery.dart';
|
||||
import 'status.dart';
|
||||
import 'tags.dart';
|
||||
@@ -191,6 +192,14 @@ abstract class _EHApi {
|
||||
{@Part(name: "is_nsfw") bool? isNsfw,
|
||||
@Part(name: "is_ad") bool? isAd,
|
||||
@CancelRequest() CancelToken? cancel});
|
||||
|
||||
@GET('/config')
|
||||
Future<Config> getConfig(
|
||||
{@Query("current") bool? current, @CancelRequest() CancelToken? cancel});
|
||||
@POST('/config')
|
||||
Future<UpdateConfigResult> updateConfig(
|
||||
@Body(nullToAbsent: false) ConfigOptional cfg,
|
||||
{@CancelRequest() CancelToken? cancel});
|
||||
}
|
||||
|
||||
class EHApi extends __EHApi {
|
||||
|
||||
@@ -857,6 +857,71 @@ class __EHApi implements _EHApi {
|
||||
return value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Config> getConfig({
|
||||
bool? current,
|
||||
CancelToken? cancel,
|
||||
}) async {
|
||||
const _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{r'current': current};
|
||||
queryParameters.removeWhere((k, v) => v == null);
|
||||
final _headers = <String, dynamic>{};
|
||||
final Map<String, dynamic>? _data = null;
|
||||
final _result =
|
||||
await _dio.fetch<Map<String, dynamic>>(_setStreamType<Config>(Options(
|
||||
method: 'GET',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/config',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
cancelToken: cancel,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final value = Config.fromJson(_result.data!);
|
||||
return value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UpdateConfigResult> updateConfig(
|
||||
ConfigOptional cfg, {
|
||||
CancelToken? cancel,
|
||||
}) async {
|
||||
const _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
queryParameters.removeWhere((k, v) => v == null);
|
||||
final _headers = <String, dynamic>{};
|
||||
final _data = <String, dynamic>{};
|
||||
_data.addAll(cfg.toJson());
|
||||
final _result = await _dio
|
||||
.fetch<Map<String, dynamic>>(_setStreamType<UpdateConfigResult>(Options(
|
||||
method: 'POST',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/config',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
cancelToken: cancel,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final value = UpdateConfigResult.fromJson(_result.data!);
|
||||
return value;
|
||||
}
|
||||
|
||||
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
|
||||
if (T != dynamic &&
|
||||
!(requestOptions.responseType == ResponseType.bytes ||
|
||||
|
||||
167
lib/api/config.dart
Normal file
167
lib/api/config.dart
Normal file
@@ -0,0 +1,167 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'config.g.dart';
|
||||
|
||||
enum ThumbnailMethod {
|
||||
@JsonValue(0)
|
||||
ffmpegBinary,
|
||||
@JsonValue(1)
|
||||
ffmpegApi,
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class Config {
|
||||
Config({
|
||||
required this.cookies,
|
||||
this.dbPath,
|
||||
this.ua,
|
||||
required this.ex,
|
||||
required this.base,
|
||||
required this.maxTaskCount,
|
||||
required this.mpv,
|
||||
required this.maxRetryCount,
|
||||
required this.maxDownloadImgCount,
|
||||
required this.downloadOriginalImg,
|
||||
required this.port,
|
||||
required this.exportZipJpnTitle,
|
||||
required this.hostname,
|
||||
this.meiliHost,
|
||||
this.meiliSearchApiKey,
|
||||
this.meiliUpdateApiKey,
|
||||
required this.ffmpegPath,
|
||||
required this.thumbnailMethod,
|
||||
required this.thumbnailDir,
|
||||
required this.removePreviousGallery,
|
||||
this.imgVerifySecret,
|
||||
this.meiliHosts,
|
||||
required this.corsCredentialsHosts,
|
||||
this.flutterFrontend,
|
||||
required this.fetchTimeout,
|
||||
required this.downloadTimeout,
|
||||
required this.ffprobePath,
|
||||
});
|
||||
bool cookies;
|
||||
@JsonKey(name: 'db_path')
|
||||
String? dbPath;
|
||||
String? ua;
|
||||
bool ex;
|
||||
String base;
|
||||
@JsonKey(name: 'max_task_count')
|
||||
int maxTaskCount;
|
||||
bool mpv;
|
||||
@JsonKey(name: 'max_retry_count')
|
||||
int maxRetryCount;
|
||||
@JsonKey(name: 'max_download_img_count')
|
||||
int maxDownloadImgCount;
|
||||
@JsonKey(name: 'download_original_img')
|
||||
bool downloadOriginalImg;
|
||||
int port;
|
||||
@JsonKey(name: 'export_zip_jpn_title')
|
||||
bool exportZipJpnTitle;
|
||||
String hostname;
|
||||
@JsonKey(name: 'meili_host')
|
||||
String? meiliHost;
|
||||
@JsonKey(name: 'meili_search_api_key')
|
||||
String? meiliSearchApiKey;
|
||||
@JsonKey(name: 'meili_update_api_key')
|
||||
String? meiliUpdateApiKey;
|
||||
@JsonKey(name: 'ffmpeg_path')
|
||||
String ffmpegPath;
|
||||
@JsonKey(name: 'thumbnail_method')
|
||||
ThumbnailMethod thumbnailMethod;
|
||||
@JsonKey(name: 'thumbnail_dir')
|
||||
String thumbnailDir;
|
||||
@JsonKey(name: 'remove_previous_gallery')
|
||||
bool removePreviousGallery;
|
||||
@JsonKey(name: 'img_verify_secret')
|
||||
String? imgVerifySecret;
|
||||
@JsonKey(name: 'meili_hosts')
|
||||
Map<String, String>? meiliHosts;
|
||||
@JsonKey(name: 'cors_credentials_hosts')
|
||||
List<String> corsCredentialsHosts;
|
||||
@JsonKey(name: 'flutter_frontend')
|
||||
String? flutterFrontend;
|
||||
@JsonKey(name: 'fetch_timeout')
|
||||
int fetchTimeout;
|
||||
@JsonKey(name: 'download_timeout')
|
||||
int downloadTimeout;
|
||||
@JsonKey(name: 'ffprobe_path')
|
||||
String ffprobePath;
|
||||
factory Config.fromJson(Map<String, dynamic> json) => _$ConfigFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ConfigToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class UpdateConfigResult {
|
||||
const UpdateConfigResult({
|
||||
required this.isUnsafe,
|
||||
});
|
||||
@JsonKey(name: 'is_unsafe')
|
||||
final bool isUnsafe;
|
||||
factory UpdateConfigResult.fromJson(Map<String, dynamic> json) =>
|
||||
_$UpdateConfigResultFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$UpdateConfigResultToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ConfigOptional {
|
||||
ConfigOptional({
|
||||
this.cookies,
|
||||
this.dbPath,
|
||||
this.ua,
|
||||
this.ex,
|
||||
this.base,
|
||||
this.maxTaskCount,
|
||||
this.mpv,
|
||||
this.maxRetryCount,
|
||||
this.maxDownloadImgCount,
|
||||
this.downloadOriginalImg,
|
||||
this.port,
|
||||
this.exportZipJpnTitle,
|
||||
this.hostname,
|
||||
this.meiliHost,
|
||||
this.meiliSearchApiKey,
|
||||
this.meiliUpdateApiKey,
|
||||
this.ffmpegPath,
|
||||
this.thumbnailMethod,
|
||||
this.thumbnailDir,
|
||||
this.removePreviousGallery,
|
||||
this.imgVerifySecret,
|
||||
this.meiliHosts,
|
||||
this.corsCredentialsHosts,
|
||||
this.flutterFrontend,
|
||||
this.fetchTimeout,
|
||||
this.downloadTimeout,
|
||||
this.ffprobePath,
|
||||
});
|
||||
String? cookies;
|
||||
String? dbPath;
|
||||
String? ua;
|
||||
bool? ex;
|
||||
String? base;
|
||||
int? maxTaskCount;
|
||||
bool? mpv;
|
||||
int? maxRetryCount;
|
||||
int? maxDownloadImgCount;
|
||||
bool? downloadOriginalImg;
|
||||
int? port;
|
||||
bool? exportZipJpnTitle;
|
||||
String? hostname;
|
||||
String? meiliHost;
|
||||
String? meiliSearchApiKey;
|
||||
String? meiliUpdateApiKey;
|
||||
String? ffmpegPath;
|
||||
ThumbnailMethod? thumbnailMethod;
|
||||
String? thumbnailDir;
|
||||
bool? removePreviousGallery;
|
||||
String? imgVerifySecret;
|
||||
Map<String, String>? meiliHosts;
|
||||
List<String>? corsCredentialsHosts;
|
||||
String? flutterFrontend;
|
||||
int? fetchTimeout;
|
||||
int? downloadTimeout;
|
||||
String? ffprobePath;
|
||||
factory ConfigOptional.fromJson(Map<String, dynamic> json) =>
|
||||
_$ConfigOptionalFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ConfigOptionalToJson(this);
|
||||
}
|
||||
154
lib/api/config.g.dart
Normal file
154
lib/api/config.g.dart
Normal file
@@ -0,0 +1,154 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'config.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Config _$ConfigFromJson(Map<String, dynamic> json) => Config(
|
||||
cookies: json['cookies'] as bool,
|
||||
dbPath: json['db_path'] as String?,
|
||||
ua: json['ua'] as String?,
|
||||
ex: json['ex'] as bool,
|
||||
base: json['base'] as String,
|
||||
maxTaskCount: json['max_task_count'] as int,
|
||||
mpv: json['mpv'] as bool,
|
||||
maxRetryCount: json['max_retry_count'] as int,
|
||||
maxDownloadImgCount: json['max_download_img_count'] as int,
|
||||
downloadOriginalImg: json['download_original_img'] as bool,
|
||||
port: json['port'] as int,
|
||||
exportZipJpnTitle: json['export_zip_jpn_title'] as bool,
|
||||
hostname: json['hostname'] as String,
|
||||
meiliHost: json['meili_host'] as String?,
|
||||
meiliSearchApiKey: json['meili_search_api_key'] as String?,
|
||||
meiliUpdateApiKey: json['meili_update_api_key'] as String?,
|
||||
ffmpegPath: json['ffmpeg_path'] as String,
|
||||
thumbnailMethod:
|
||||
$enumDecode(_$ThumbnailMethodEnumMap, json['thumbnail_method']),
|
||||
thumbnailDir: json['thumbnail_dir'] as String,
|
||||
removePreviousGallery: json['remove_previous_gallery'] as bool,
|
||||
imgVerifySecret: json['img_verify_secret'] as String?,
|
||||
meiliHosts: (json['meili_hosts'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as String),
|
||||
),
|
||||
corsCredentialsHosts: (json['cors_credentials_hosts'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList(),
|
||||
flutterFrontend: json['flutter_frontend'] as String?,
|
||||
fetchTimeout: json['fetch_timeout'] as int,
|
||||
downloadTimeout: json['download_timeout'] as int,
|
||||
ffprobePath: json['ffprobe_path'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ConfigToJson(Config instance) => <String, dynamic>{
|
||||
'cookies': instance.cookies,
|
||||
'db_path': instance.dbPath,
|
||||
'ua': instance.ua,
|
||||
'ex': instance.ex,
|
||||
'base': instance.base,
|
||||
'max_task_count': instance.maxTaskCount,
|
||||
'mpv': instance.mpv,
|
||||
'max_retry_count': instance.maxRetryCount,
|
||||
'max_download_img_count': instance.maxDownloadImgCount,
|
||||
'download_original_img': instance.downloadOriginalImg,
|
||||
'port': instance.port,
|
||||
'export_zip_jpn_title': instance.exportZipJpnTitle,
|
||||
'hostname': instance.hostname,
|
||||
'meili_host': instance.meiliHost,
|
||||
'meili_search_api_key': instance.meiliSearchApiKey,
|
||||
'meili_update_api_key': instance.meiliUpdateApiKey,
|
||||
'ffmpeg_path': instance.ffmpegPath,
|
||||
'thumbnail_method': _$ThumbnailMethodEnumMap[instance.thumbnailMethod]!,
|
||||
'thumbnail_dir': instance.thumbnailDir,
|
||||
'remove_previous_gallery': instance.removePreviousGallery,
|
||||
'img_verify_secret': instance.imgVerifySecret,
|
||||
'meili_hosts': instance.meiliHosts,
|
||||
'cors_credentials_hosts': instance.corsCredentialsHosts,
|
||||
'flutter_frontend': instance.flutterFrontend,
|
||||
'fetch_timeout': instance.fetchTimeout,
|
||||
'download_timeout': instance.downloadTimeout,
|
||||
'ffprobe_path': instance.ffprobePath,
|
||||
};
|
||||
|
||||
const _$ThumbnailMethodEnumMap = {
|
||||
ThumbnailMethod.ffmpegBinary: 0,
|
||||
ThumbnailMethod.ffmpegApi: 1,
|
||||
};
|
||||
|
||||
UpdateConfigResult _$UpdateConfigResultFromJson(Map<String, dynamic> json) =>
|
||||
UpdateConfigResult(
|
||||
isUnsafe: json['is_unsafe'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$UpdateConfigResultToJson(UpdateConfigResult instance) =>
|
||||
<String, dynamic>{
|
||||
'is_unsafe': instance.isUnsafe,
|
||||
};
|
||||
|
||||
ConfigOptional _$ConfigOptionalFromJson(Map<String, dynamic> json) =>
|
||||
ConfigOptional(
|
||||
cookies: json['cookies'] as String?,
|
||||
dbPath: json['dbPath'] as String?,
|
||||
ua: json['ua'] as String?,
|
||||
ex: json['ex'] as bool?,
|
||||
base: json['base'] as String?,
|
||||
maxTaskCount: json['maxTaskCount'] as int?,
|
||||
mpv: json['mpv'] as bool?,
|
||||
maxRetryCount: json['maxRetryCount'] as int?,
|
||||
maxDownloadImgCount: json['maxDownloadImgCount'] as int?,
|
||||
downloadOriginalImg: json['downloadOriginalImg'] as bool?,
|
||||
port: json['port'] as int?,
|
||||
exportZipJpnTitle: json['exportZipJpnTitle'] as bool?,
|
||||
hostname: json['hostname'] as String?,
|
||||
meiliHost: json['meiliHost'] as String?,
|
||||
meiliSearchApiKey: json['meiliSearchApiKey'] as String?,
|
||||
meiliUpdateApiKey: json['meiliUpdateApiKey'] as String?,
|
||||
ffmpegPath: json['ffmpegPath'] as String?,
|
||||
thumbnailMethod: $enumDecodeNullable(
|
||||
_$ThumbnailMethodEnumMap, json['thumbnailMethod']),
|
||||
thumbnailDir: json['thumbnailDir'] as String?,
|
||||
removePreviousGallery: json['removePreviousGallery'] as bool?,
|
||||
imgVerifySecret: json['imgVerifySecret'] as String?,
|
||||
meiliHosts: (json['meiliHosts'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as String),
|
||||
),
|
||||
corsCredentialsHosts: (json['corsCredentialsHosts'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList(),
|
||||
flutterFrontend: json['flutterFrontend'] as String?,
|
||||
fetchTimeout: json['fetchTimeout'] as int?,
|
||||
downloadTimeout: json['downloadTimeout'] as int?,
|
||||
ffprobePath: json['ffprobePath'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ConfigOptionalToJson(ConfigOptional instance) =>
|
||||
<String, dynamic>{
|
||||
'cookies': instance.cookies,
|
||||
'dbPath': instance.dbPath,
|
||||
'ua': instance.ua,
|
||||
'ex': instance.ex,
|
||||
'base': instance.base,
|
||||
'maxTaskCount': instance.maxTaskCount,
|
||||
'mpv': instance.mpv,
|
||||
'maxRetryCount': instance.maxRetryCount,
|
||||
'maxDownloadImgCount': instance.maxDownloadImgCount,
|
||||
'downloadOriginalImg': instance.downloadOriginalImg,
|
||||
'port': instance.port,
|
||||
'exportZipJpnTitle': instance.exportZipJpnTitle,
|
||||
'hostname': instance.hostname,
|
||||
'meiliHost': instance.meiliHost,
|
||||
'meiliSearchApiKey': instance.meiliSearchApiKey,
|
||||
'meiliUpdateApiKey': instance.meiliUpdateApiKey,
|
||||
'ffmpegPath': instance.ffmpegPath,
|
||||
'thumbnailMethod': _$ThumbnailMethodEnumMap[instance.thumbnailMethod],
|
||||
'thumbnailDir': instance.thumbnailDir,
|
||||
'removePreviousGallery': instance.removePreviousGallery,
|
||||
'imgVerifySecret': instance.imgVerifySecret,
|
||||
'meiliHosts': instance.meiliHosts,
|
||||
'corsCredentialsHosts': instance.corsCredentialsHosts,
|
||||
'flutterFrontend': instance.flutterFrontend,
|
||||
'fetchTimeout': instance.fetchTimeout,
|
||||
'downloadTimeout': instance.downloadTimeout,
|
||||
'ffprobePath': instance.ffprobePath,
|
||||
};
|
||||
Reference in New Issue
Block a user