Skip to content

Commit

Permalink
Add new server settings
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc authored Jun 8, 2024
1 parent eacff10 commit 418a273
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 2 deletions.
51 changes: 51 additions & 0 deletions lib/api/config.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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({
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions lib/api/config.g.dart

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

10 changes: 9 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,13 @@
"thumbnailSize": "Thumbnail size",
"smail": "smail",
"medium": "medium",
"big": "big"
"big": "big",
"usePathBasedImgUrl": "Put parameters to image URL path.",
"checkFileHash": "Verify file integrity when downloading or importing.",
"importMethod": "Import method",
"copy": "Copy",
"copyThenDelete": "Copy then delete",
"move": "Move",
"keep": "Keep",
"maxImportImgCount": "Maximum number of images to be imported in parallel"
}
10 changes: 9 additions & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,13 @@
"thumbnailSize": "缩略图大小",
"smail": "小",
"medium": "中",
"big": "大"
"big": "大",
"usePathBasedImgUrl": "将参数放入图片地址路径。",
"checkFileHash": "下载或导入时校验文件完整性。",
"importMethod": "导入方式",
"copy": "复制",
"copyThenDelete": "复制后删除",
"move": "移动",
"keep": "保留",
"maxImportImgCount": "最大图片并行导入数"
}
54 changes: 54 additions & 0 deletions lib/pages/settings/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,28 @@ class _ServerSettingsPage extends State<ServerSettingsPage>
}
},
label: Text(i18n.redirectToFlutter))),
_buildWithVecticalPadding(LabeledCheckbox(
value: _now.usePathBasedImgUrl ?? _config!.usePathBasedImgUrl,
onChanged: (b) {
if (b != null) {
setState(() {
_now.usePathBasedImgUrl = b;
_changed = true;
});
}
},
label: Text(i18n.usePathBasedImgUrl))),
_buildWithVecticalPadding(LabeledCheckbox(
value: _now.checkFileHash ?? _config!.checkFileHash,
onChanged: (b) {
if (b != null) {
setState(() {
_now.checkFileHash = b;
_changed = true;
});
}
},
label: Text(i18n.checkFileHash))),
]));
}

Expand Down Expand Up @@ -721,6 +743,38 @@ class _ServerSettingsPage extends State<ServerSettingsPage>
});
},
)),
_buildWithVecticalPadding(DropdownButtonFormField<ImportMethod>(
items: ImportMethod.values
.map((e) => DropdownMenuItem(
value: e, child: Text(e.localText(context))))
.toList(),
onChanged: (v) {
if (v != null) {
setState(() {
_now.importMethod = v;
_changed = true;
});
}
},
value: _now.importMethod ?? _config!.importMethod,
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText: i18n.importMethod,
))),
_buildWithVecticalPadding(NumberFormField(
min: 1,
initialValue: _now.maxImportImgCount ?? _config!.maxImportImgCount,
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText: i18n.maxImportImgCount,
),
onChanged: (s) {
setState(() {
_now.maxImportImgCount = s;
_changed = true;
});
},
)),
]));
}

Expand Down

0 comments on commit 418a273

Please sign in to comment.