Add new server settings

This commit is contained in:
2024-06-08 13:52:08 +00:00
committed by GitHub
parent eacff10594
commit 418a27347f
5 changed files with 147 additions and 2 deletions

View File

@@ -1,3 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:json_annotation/json_annotation.dart';
part 'config.g.dart';
@@ -9,6 +11,31 @@ enum ThumbnailMethod {
ffmpegApi,
}
enum ImportMethod {
@JsonValue(0)
copy,
@JsonValue(1)
copyThenDelete,
@JsonValue(2)
move,
@JsonValue(3)
keep;
String localText(BuildContext context) {
final i18n = AppLocalizations.of(context)!;
switch (this) {
case ImportMethod.copy:
return i18n.copy;
case ImportMethod.copyThenDelete:
return i18n.copyThenDelete;
case ImportMethod.move:
return i18n.move;
case ImportMethod.keep:
return i18n.keep;
}
}
}
@JsonSerializable()
class Config {
Config({
@@ -43,6 +70,10 @@ class Config {
required this.downloadTimeoutCheckInterval,
required this.ehMetadataCacheTime,
this.randomFileSecret,
required this.usePathBasedImgUrl,
required this.checkFileHash,
required this.importMethod,
required this.maxImportImgCount,
});
bool cookies;
@JsonKey(name: 'db_path')
@@ -99,6 +130,14 @@ class Config {
int ehMetadataCacheTime;
@JsonKey(name: "random_file_secret")
String? randomFileSecret;
@JsonKey(name: 'use_path_based_img_url')
bool usePathBasedImgUrl;
@JsonKey(name: 'check_file_hash')
bool checkFileHash;
@JsonKey(name: 'import_method')
ImportMethod importMethod;
@JsonKey(name: 'max_import_img_count')
int maxImportImgCount;
factory Config.fromJson(Map<String, dynamic> json) => _$ConfigFromJson(json);
Map<String, dynamic> toJson() => _$ConfigToJson(this);
}
@@ -149,6 +188,10 @@ class ConfigOptional {
this.downloadTimeoutCheckInterval,
this.ehMetadataCacheTime,
this.randomFileSecret,
this.usePathBasedImgUrl,
this.checkFileHash,
this.importMethod,
this.maxImportImgCount,
});
String? cookies;
@JsonKey(name: 'db_path')
@@ -205,6 +248,14 @@ class ConfigOptional {
int? ehMetadataCacheTime;
@JsonKey(name: "random_file_secret")
String? randomFileSecret;
@JsonKey(name: 'use_path_based_img_url')
bool? usePathBasedImgUrl;
@JsonKey(name: 'check_file_hash')
bool? checkFileHash;
@JsonKey(name: 'import_method')
ImportMethod? importMethod;
@JsonKey(name: 'max_import_img_count')
int? maxImportImgCount;
factory ConfigOptional.fromJson(Map<String, dynamic> json) =>
_$ConfigOptionalFromJson(json);
Map<String, dynamic> toJson() => _$ConfigOptionalToJson(this);

View File

@@ -44,6 +44,10 @@ Config _$ConfigFromJson(Map<String, dynamic> json) => Config(
(json['download_timeout_check_interval'] as num).toInt(),
ehMetadataCacheTime: (json['eh_metadata_cache_time'] as num).toInt(),
randomFileSecret: json['random_file_secret'] as String?,
usePathBasedImgUrl: json['use_path_based_img_url'] as bool,
checkFileHash: json['check_file_hash'] as bool,
importMethod: $enumDecode(_$ImportMethodEnumMap, json['import_method']),
maxImportImgCount: (json['max_import_img_count'] as num).toInt(),
);
Map<String, dynamic> _$ConfigToJson(Config instance) => <String, dynamic>{
@@ -78,6 +82,10 @@ Map<String, dynamic> _$ConfigToJson(Config instance) => <String, dynamic>{
'download_timeout_check_interval': instance.downloadTimeoutCheckInterval,
'eh_metadata_cache_time': instance.ehMetadataCacheTime,
'random_file_secret': instance.randomFileSecret,
'use_path_based_img_url': instance.usePathBasedImgUrl,
'check_file_hash': instance.checkFileHash,
'import_method': _$ImportMethodEnumMap[instance.importMethod]!,
'max_import_img_count': instance.maxImportImgCount,
};
const _$ThumbnailMethodEnumMap = {
@@ -85,6 +93,13 @@ const _$ThumbnailMethodEnumMap = {
ThumbnailMethod.ffmpegApi: 1,
};
const _$ImportMethodEnumMap = {
ImportMethod.copy: 0,
ImportMethod.copyThenDelete: 1,
ImportMethod.move: 2,
ImportMethod.keep: 3,
};
UpdateConfigResult _$UpdateConfigResultFromJson(Map<String, dynamic> json) =>
UpdateConfigResult(
isUnsafe: json['is_unsafe'] as bool,
@@ -134,6 +149,11 @@ ConfigOptional _$ConfigOptionalFromJson(Map<String, dynamic> json) =>
(json['download_timeout_check_interval'] as num?)?.toInt(),
ehMetadataCacheTime: (json['eh_metadata_cache_time'] as num?)?.toInt(),
randomFileSecret: json['random_file_secret'] as String?,
usePathBasedImgUrl: json['use_path_based_img_url'] as bool?,
checkFileHash: json['check_file_hash'] as bool?,
importMethod:
$enumDecodeNullable(_$ImportMethodEnumMap, json['import_method']),
maxImportImgCount: (json['max_import_img_count'] as num?)?.toInt(),
);
Map<String, dynamic> _$ConfigOptionalToJson(ConfigOptional instance) =>
@@ -169,4 +189,8 @@ Map<String, dynamic> _$ConfigOptionalToJson(ConfigOptional instance) =>
'download_timeout_check_interval': instance.downloadTimeoutCheckInterval,
'eh_metadata_cache_time': instance.ehMetadataCacheTime,
'random_file_secret': instance.randomFileSecret,
'use_path_based_img_url': instance.usePathBasedImgUrl,
'check_file_hash': instance.checkFileHash,
'import_method': _$ImportMethodEnumMap[instance.importMethod],
'max_import_img_count': instance.maxImportImgCount,
};