Skip to content

Commit

Permalink
Add server settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc committed Jan 1, 2024
1 parent 5566af9 commit 6644e78
Show file tree
Hide file tree
Showing 10 changed files with 695 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/api/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down
65 changes: 65 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.

167 changes: 167 additions & 0 deletions lib/api/config.dart
Original file line number Diff line number Diff line change
@@ -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);
}
Loading

0 comments on commit 6644e78

Please sign in to comment.