Compare commits

...

12 Commits

16 changed files with 291 additions and 162 deletions

View File

@ -12,6 +12,7 @@
### Changes from v2.0.4-rc ### Changes from v2.0.4-rc
* Continue documentation updates * Continue documentation updates
* Require `--name,-na` option for encryption provider
## v2.0.4-rc ## v2.0.4-rc

View File

@ -36,10 +36,9 @@ template <typename drive> inline void help(std::vector<const char *> args) {
std::cout << " -di,--drive_information Display mounted drive " std::cout << " -di,--drive_information Display mounted drive "
"information" "information"
<< std::endl; << std::endl;
std::cout std::cout << " -na,--name Unique configuration "
<< " -na,--name Unique name for S3 or Sia " "name [Required for Encrypt, S3 and Sia]"
"instance [Required]" << std::endl;
<< std::endl;
std::cout << " -s3,--s3 Enables S3 mode" std::cout << " -s3,--s3 Enables S3 mode"
<< std::endl; << std::endl;
std::cout std::cout

View File

@ -105,7 +105,8 @@ auto main(int argc, char **argv) -> int {
} }
} }
} }
} else if ((prov == provider_type::s3) || (prov == provider_type::sia)) { } else if ((prov == provider_type::s3) || (prov == provider_type::sia) ||
(prov == provider_type::encrypt)) {
std::string data; std::string data;
res = utils::cli::parse_string_option( res = utils::cli::parse_string_option(
args, utils::cli::options::name_option, data); args, utils::cli::options::name_option, data);
@ -115,9 +116,9 @@ auto main(int argc, char **argv) -> int {
if (prov == provider_type::sia) { if (prov == provider_type::sia) {
unique_id = "default"; unique_id = "default";
} else { } else {
std::cerr << "Name of " std::cerr << "Configuration name for '"
<< app_config::get_provider_display_name(prov) << app_config::get_provider_display_name(prov)
<< " instance not provided" << std::endl; << "' was not provided" << std::endl;
res = exit_code::invalid_syntax; res = exit_code::invalid_syntax;
} }
} }

View File

@ -171,12 +171,6 @@ void handlers::handle_get_mount_list(auto &&res) const {
auto data_dir = utils::file::directory{app_config::get_root_data_directory()}; auto data_dir = utils::file::directory{app_config::get_root_data_directory()};
nlohmann::json result; nlohmann::json result;
auto encrypt_dir = data_dir.get_directory("encrypt");
if (encrypt_dir && encrypt_dir->get_file("config.json")) {
result["encrypt"].emplace_back("encrypt");
}
const auto process_dir = [&data_dir, &result](std::string_view name) { const auto process_dir = [&data_dir, &result](std::string_view name) {
auto name_dir = data_dir.get_directory(name); auto name_dir = data_dir.get_directory(name);
if (not name_dir) { if (not name_dir) {
@ -193,6 +187,7 @@ void handlers::handle_get_mount_list(auto &&res) const {
} }
}; };
process_dir("encrypt");
process_dir("remote"); process_dir("remote");
process_dir("s3"); process_dir("s3");
process_dir("sia"); process_dir("sia");
@ -223,14 +218,12 @@ void handlers::handle_get_mount_status(auto &&req, auto &&res) const {
auto status_name = app_config::get_provider_display_name(prov); auto status_name = app_config::get_provider_display_name(prov);
switch (prov) { switch (prov) {
case provider_type::encrypt:
break;
case provider_type::remote: { case provider_type::remote: {
auto parts = utils::string::split(name, '_', false); auto parts = utils::string::split(name, '_', false);
status_name = fmt::format("{}{}:{}", status_name, parts[0U], parts[1U]); status_name = fmt::format("{}{}:{}", status_name, parts[0U], parts[1U]);
} break; } break;
case provider_type::encrypt:
case provider_type::sia: case provider_type::sia:
case provider_type::s3: case provider_type::s3:
status_name = fmt::format("{}{}", status_name, name); status_name = fmt::format("{}{}", status_name, name);
@ -305,7 +298,7 @@ auto handlers::launch_process(provider_type prov, std::string_view name,
std::string str_type; std::string str_type;
switch (prov) { switch (prov) {
case provider_type::encrypt: case provider_type::encrypt:
str_type = "-en"; str_type = fmt::format("-en -na {}", name);
break; break;
case provider_type::remote: { case provider_type::remote: {

View File

@ -35,12 +35,16 @@ namespace {
std::unordered_map<repertory::provider_type, std::unordered_map<repertory::provider_type,
std::unordered_map<std::string, std::string>> std::unordered_map<std::string, std::string>>
map_of_maps{ map_of_maps{
{repertory::provider_type::encrypt, {}}, {repertory::provider_type::encrypt, nlohmann::json::object()},
{repertory::provider_type::remote, {}}, {repertory::provider_type::remote, nlohmann::json::object()},
{repertory::provider_type::s3, {}}, {repertory::provider_type::s3, nlohmann::json::object()},
{repertory::provider_type::sia, {}}, {repertory::provider_type::sia, nlohmann::json::object()},
}; };
if (json.is_null() || json.empty()) {
return map_of_maps;
}
for (const auto &[prov, map] : map_of_maps) { for (const auto &[prov, map] : map_of_maps) {
for (const auto &[key, value] : for (const auto &[key, value] :
json[repertory::provider_type_to_string(prov)].items()) { json[repertory::provider_type_to_string(prov)].items()) {
@ -56,7 +60,7 @@ namespace {
} }
[[nodiscard]] auto to_json(const auto &map_of_maps) -> nlohmann::json { [[nodiscard]] auto to_json(const auto &map_of_maps) -> nlohmann::json {
nlohmann::json json; auto json = nlohmann::json::object();
for (const auto &[prov, map] : map_of_maps) { for (const auto &[prov, map] : map_of_maps) {
for (const auto &[key, value] : map) { for (const auto &[key, value] : map) {
json[repertory::provider_type_to_string(prov)][key] = value; json[repertory::provider_type_to_string(prov)][key] = value;
@ -75,9 +79,18 @@ mgmt_app_config::mgmt_app_config() {
utils::path::combine(app_config::get_root_data_directory(), {"ui.json"}); utils::path::combine(app_config::get_root_data_directory(), {"ui.json"});
try { try {
if (not utils::file::directory{app_config::get_root_data_directory()}
.create_directory()) {
throw utils::error::create_exception(
function_name, {
"failed to create directory",
app_config::get_root_data_directory(),
});
}
nlohmann::json data; nlohmann::json data;
if (utils::file::read_json_file(config_file, data)) { if (utils::file::read_json_file(config_file, data)) {
api_auth_ = data.at(JSON_API_AUTH).get<std::string>(); api_auth_ = data.at(JSON_API_PASSWORD).get<std::string>();
api_port_ = data.at(JSON_API_PORT).get<std::uint16_t>(); api_port_ = data.at(JSON_API_PORT).get<std::uint16_t>();
api_user_ = data.at(JSON_API_USER).get<std::string>(); api_user_ = data.at(JSON_API_USER).get<std::string>();
locations_ = from_json(data.at(JSON_MOUNT_LOCATIONS)); locations_ = from_json(data.at(JSON_MOUNT_LOCATIONS));
@ -87,6 +100,7 @@ mgmt_app_config::mgmt_app_config() {
utils::error::raise_error( utils::error::raise_error(
function_name, utils::get_last_error_code(), function_name, utils::get_last_error_code(),
fmt::format("failed to read file|{}", config_file)); fmt::format("failed to read file|{}", config_file));
save();
} catch (const std::exception &ex) { } catch (const std::exception &ex) {
utils::error::raise_error( utils::error::raise_error(
function_name, ex, fmt::format("failed to read file|{}", config_file)); function_name, ex, fmt::format("failed to read file|{}", config_file));
@ -121,7 +135,7 @@ void mgmt_app_config::save() const {
} }
nlohmann::json data; nlohmann::json data;
data[JSON_API_AUTH] = api_auth_; data[JSON_API_PASSWORD] = api_auth_;
data[JSON_API_PORT] = api_port_; data[JSON_API_PORT] = api_port_;
data[JSON_API_USER] = api_user_; data[JSON_API_USER] = api_user_;
data[JSON_MOUNT_LOCATIONS] = to_json(locations_); data[JSON_MOUNT_LOCATIONS] = to_json(locations_);

View File

@ -1,4 +1,6 @@
autofocus
cupertino cupertino
cupertinoicons cupertinoicons
fromargb fromargb
onetwothree onetwothree
rocksdb

View File

@ -1 +1 @@
const String appTitle = "Repertory Management Portal"; const String appTitle = 'Repertory Management Portal';

View File

@ -1,15 +1,15 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
String formatMountName(String type, String name) { String formatMountName(String type, String name) {
if (type == "remote") { if (type == 'remote') {
return name.replaceAll("_", ":"); return name.replaceAll('_', ':');
} }
return name; return name;
} }
String getBaseUri() { String getBaseUri() {
if (kDebugMode) { if (kDebugMode) {
return "http://127.0.0.1:30000"; return 'http://127.0.0.1:30000';
} }
return Uri.base.origin; return Uri.base.origin;
} }

View File

@ -1,11 +1,9 @@
import 'package:collection/collection.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:repertory/constants.dart' as constants; import 'package:repertory/constants.dart' as constants;
import 'package:repertory/helpers.dart'; import 'package:repertory/helpers.dart';
import 'package:repertory/models/mount.dart'; import 'package:repertory/models/mount.dart';
import 'package:repertory/models/mount_list.dart'; import 'package:repertory/models/mount_list.dart';
import 'package:repertory/types/mount_config.dart';
import 'package:repertory/widgets/add_mount_widget.dart'; import 'package:repertory/widgets/add_mount_widget.dart';
import 'package:repertory/widgets/mount_list_widget.dart'; import 'package:repertory/widgets/mount_list_widget.dart';
import 'package:repertory/widgets/mount_settings.dart'; import 'package:repertory/widgets/mount_settings.dart';
@ -20,7 +18,7 @@ class MyApp extends StatelessWidget {
const MyApp({super.key}); const MyApp({super.key});
@override @override
Widget build(BuildContext context) { Widget build(context) {
return MaterialApp( return MaterialApp(
title: constants.appTitle, title: constants.appTitle,
theme: ThemeData( theme: ThemeData(
@ -78,11 +76,64 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
bool _allowAdd = true; bool _allowAdd = true;
String _mountType = "S3"; String? _apiPassword;
String? _apiPort;
String? _bucket;
String? _encryptionToken;
String? _hostNameOrIp;
String _mountType = 'Encrypt';
String _mountName = ""; String _mountName = "";
String? _path;
void _resetData() {
_apiPassword = null;
_apiPort = null;
_bucket = null;
_encryptionToken = null;
_hostNameOrIp = null;
_mountName = "";
_mountType = 'Encrypt';
_path = null;
}
void _updateData(String name, String? value) {
switch (name) {
case 'ApiPassword':
_apiPassword = value ?? '';
return;
case 'ApiPort':
_apiPort = value ?? '';
return;
case 'Bucket':
_bucket = value ?? '';
return;
case 'EncryptionToken':
_encryptionToken = value ?? '';
return;
case 'HostNameOrIp':
_hostNameOrIp = value ?? '';
return;
case 'Name':
_mountName = value ?? '';
return;
case 'Provider':
_mountType = value ?? 'Encrypt';
return;
case 'Path':
_path = value ?? '';
return;
}
}
@override @override
Widget build(BuildContext context) { Widget build(context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary, backgroundColor: Theme.of(context).colorScheme.inversePrimary,
@ -96,25 +147,14 @@ class _MyHomePageState extends State<MyHomePage> {
? () { ? () {
showDialog( showDialog(
context: context, context: context,
builder: (BuildContext context) { builder: (context) {
return AlertDialog( return AlertDialog(
title: const Text('Add Mount'), title: const Text('Add Mount'),
content: Consumer<MountList>( content: Consumer<MountList>(
builder: (_, mountList, __) { builder: (_, MountList mountList, __) {
return AddMountWidget( return AddMountWidget(
allowEncrypt:
mountList.items.firstWhereOrNull(
(MountConfig item) =>
item.type.toLowerCase() == "encrypt",
) ==
null,
mountType: _mountType, mountType: _mountType,
onNameChanged: (mountName) { onDataChanged: _updateData,
_mountName = mountName ?? "";
},
onTypeChanged: (mountType) {
_mountType = mountType ?? "S3";
},
); );
}, },
), ),
@ -122,8 +162,7 @@ class _MyHomePageState extends State<MyHomePage> {
TextButton( TextButton(
child: const Text('Cancel'), child: const Text('Cancel'),
onPressed: () { onPressed: () {
_mountType = "S3"; _resetData();
_mountName = "";
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),
@ -133,10 +172,18 @@ class _MyHomePageState extends State<MyHomePage> {
setState(() => _allowAdd = false); setState(() => _allowAdd = false);
Provider.of<MountList>(context, listen: false) Provider.of<MountList>(context, listen: false)
.add(_mountType, _mountName) .add(
_mountType,
_mountName,
apiPassword: _apiPassword,
apiPort: _apiPort,
bucket: _bucket,
encryptionToken: _encryptionToken,
hostNameOrIp: _hostNameOrIp,
path: _path,
)
.then((_) { .then((_) {
_mountType = "S3"; _resetData();
_mountName = "";
setState(() { setState(() {
_allowAdd = true; _allowAdd = true;
}); });
@ -159,4 +206,13 @@ class _MyHomePageState extends State<MyHomePage> {
), ),
); );
} }
@override
void setState(VoidCallback fn) {
if (!mounted) {
return;
}
super.setState(fn);
}
} }

View File

@ -79,6 +79,18 @@ class Mount with ChangeNotifier {
} }
Future<String?> getMountLocation() async { Future<String?> getMountLocation() async {
return "~/mnt/encrypt"; final response = await http.get(
Uri.parse(
Uri.encodeFull(
'${getBaseUri()}/api/v1/get_mount_location?name=$name&type=$type',
),
),
);
if (response.statusCode != 200) {
return null;
}
return jsonDecode(response.body)['Location'] as String;
} }
} }

View File

@ -48,11 +48,22 @@ class MountList with ChangeNotifier {
}); });
} }
Future<void> add(String type, String name) async { Future<void> add(
String type,
String name, {
String? apiPassword,
String? apiPort,
String? bucket,
String? encryptionToken,
String? hostNameOrIp,
String? path,
}) async {
await http.post( await http.post(
Uri.parse( Uri.parse(
Uri.encodeFull( Uri.encodeFull(
'${getBaseUri()}/api/v1/add_mount?name=$name&type=$type', '${getBaseUri()}/api/v1/add_mount?name=$name&type=$type&bucket=$bucket'
'&path=$path&apiPassword=$apiPassword&apiPort=$apiPort&hostNameOrIp=$hostNameOrIp'
'&encryptionToken=$encryptionToken',
), ),
), ),
); );

View File

@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
class MountConfig { class MountConfig {
final String _name; final String _name;
String _path = ""; String _path = '';
Map<String, dynamic> _settings = {}; Map<String, dynamic> _settings = {};
IconData _state = Icons.toggle_off; IconData _state = Icons.toggle_off;
final String _type; final String _type;
@ -25,7 +25,7 @@ class MountConfig {
} }
void updateStatus(Map<String, dynamic> status) { void updateStatus(Map<String, dynamic> status) {
_path = status["Location"] as String; _path = status['Location'] as String;
_state = status["Active"] as bool ? Icons.toggle_on : Icons.toggle_off; _state = status['Active'] as bool ? Icons.toggle_on : Icons.toggle_off;
} }
} }

View File

@ -1,30 +1,23 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class AddMountWidget extends StatefulWidget { class AddMountWidget extends StatefulWidget {
final bool allowEncrypt;
final String mountType; final String mountType;
final void Function(String? newName) onNameChanged; final void Function(String name, String? value) onDataChanged;
final void Function(String? newType) onTypeChanged;
final _items = <String>["S3", "Sia"]; const AddMountWidget({
AddMountWidget({
super.key, super.key,
required this.allowEncrypt,
required this.mountType, required this.mountType,
required this.onNameChanged, required this.onDataChanged,
required this.onTypeChanged, });
}) {
if (allowEncrypt) {
_items.insert(0, "Encrypt");
}
}
@override @override
State<AddMountWidget> createState() => _AddMountWidgetState(); State<AddMountWidget> createState() => _AddMountWidgetState();
} }
class _AddMountWidgetState extends State<AddMountWidget> { class _AddMountWidgetState extends State<AddMountWidget> {
static const _items = <String>['Encrypt', 'Remote', 'S3', 'Sia'];
static const _padding = 15.0;
String? _mountType; String? _mountType;
@override @override
@ -33,8 +26,33 @@ class _AddMountWidgetState extends State<AddMountWidget> {
super.initState(); super.initState();
} }
List<Widget> _createTextField(
String title,
String dataName, {
String? value,
}) {
return [
const SizedBox(height: _padding),
Text(
title,
textAlign: TextAlign.left,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.bold,
),
),
TextField(
decoration: InputDecoration(),
onChanged: (value) => widget.onDataChanged(dataName, value),
controller: TextEditingController(text: value),
),
];
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final mountTypeLower = _mountType?.toLowerCase();
return Column( return Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
@ -52,17 +70,17 @@ class _AddMountWidgetState extends State<AddMountWidget> {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
const SizedBox(width: 10), const SizedBox(width: _padding),
DropdownButton<String>( DropdownButton<String>(
value: _mountType, value: _mountType,
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
_mountType = value; _mountType = value;
}); });
widget.onTypeChanged(value); widget.onDataChanged('Provider', value);
}, },
items: items:
widget._items.map<DropdownMenuItem<String>>((item) { _items.map<DropdownMenuItem<String>>((item) {
return DropdownMenuItem<String>( return DropdownMenuItem<String>(
value: item, value: item,
child: Text(item), child: Text(item),
@ -71,22 +89,31 @@ class _AddMountWidgetState extends State<AddMountWidget> {
), ),
], ],
), ),
const SizedBox(height: 10), if (mountTypeLower != 'remote')
if (_mountType?.toLowerCase() != 'encrypt') ..._createTextField('Configuration Name', 'Name'),
Text( if (mountTypeLower == 'encrypt') ..._createTextField('Path', 'Path'),
'Configuration Name', if (mountTypeLower == 'sia')
textAlign: TextAlign.left, ..._createTextField('ApiPassword', 'ApiPassword'),
style: TextStyle( if (mountTypeLower == 's3' || mountTypeLower == 'sia')
color: Theme.of(context).colorScheme.onSurface, ..._createTextField(
fontWeight: FontWeight.bold, 'Bucket',
), 'Bucket',
value: mountTypeLower == 'sia' ? 'default' : null,
), ),
if (_mountType?.toLowerCase() != 'encrypt') if (mountTypeLower == 'remote' || mountTypeLower == 'sia')
TextField( ..._createTextField(
autofocus: true, 'HostNameOrIp',
decoration: InputDecoration(), 'HostNameOrIp',
onChanged: widget.onNameChanged, value: 'localhost',
), ),
if (mountTypeLower == 'remote' || mountTypeLower == 'sia')
..._createTextField(
'ApiPort',
'ApiPort',
value: mountTypeLower == 'sia' ? '9980' : null,
),
if (mountTypeLower == 'remote')
..._createTextField('EncryptionToken', 'EncryptionToken'),
], ],
); );
} }

View File

@ -4,14 +4,9 @@ import 'package:repertory/models/mount.dart';
import 'package:repertory/models/mount_list.dart'; import 'package:repertory/models/mount_list.dart';
import 'package:repertory/widgets/mount_widget.dart'; import 'package:repertory/widgets/mount_widget.dart';
class MountListWidget extends StatefulWidget { class MountListWidget extends StatelessWidget {
const MountListWidget({super.key}); const MountListWidget({super.key});
@override
State<MountListWidget> createState() => _MountListWidgetState();
}
class _MountListWidgetState extends State<MountListWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Consumer<MountList>( return Consumer<MountList>(

View File

@ -200,70 +200,70 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
List<SettingsTile> siaConfigSettings = []; List<SettingsTile> siaConfigSettings = [];
_settings.forEach((key, value) { _settings.forEach((key, value) {
if (key == "ApiAuth") { if (key == 'ApiAuth') {
_addPasswordSetting(commonSettings, _settings, key, value); _addPasswordSetting(commonSettings, _settings, key, value);
} else if (key == "ApiPort") { } else if (key == 'ApiPort') {
_addIntSetting(commonSettings, _settings, key, value); _addIntSetting(commonSettings, _settings, key, value);
} else if (key == "ApiUser") { } else if (key == 'ApiUser') {
_addStringSetting(commonSettings, _settings, key, value, Icons.person); _addStringSetting(commonSettings, _settings, key, value, Icons.person);
} else if (key == "DatabaseType") { } else if (key == 'DatabaseType') {
_addListSetting(commonSettings, _settings, key, value, [ _addListSetting(commonSettings, _settings, key, value, [
"rocksdb", 'rocksdb',
"sqlite", 'sqlite',
], Icons.dataset); ], Icons.dataset);
} else if (key == "DownloadTimeoutSeconds") { } else if (key == 'DownloadTimeoutSeconds') {
_addIntSetting(commonSettings, _settings, key, value); _addIntSetting(commonSettings, _settings, key, value);
} else if (key == "EnableDownloadTimeout") { } else if (key == 'EnableDownloadTimeout') {
_addBooleanSetting(commonSettings, _settings, key, value); _addBooleanSetting(commonSettings, _settings, key, value);
} else if (key == "EnableDriveEvents") { } else if (key == 'EnableDriveEvents') {
_addBooleanSetting(commonSettings, _settings, key, value); _addBooleanSetting(commonSettings, _settings, key, value);
} else if (key == "EventLevel") { } else if (key == 'EventLevel') {
_addListSetting(commonSettings, _settings, key, value, [ _addListSetting(commonSettings, _settings, key, value, [
"critical", 'critical',
"error", 'error',
"warn", 'warn',
"info", 'info',
"debug", 'debug',
"trace", 'trace',
], Icons.event); ], Icons.event);
} else if (key == "EvictionDelayMinutes") { } else if (key == 'EvictionDelayMinutes') {
_addIntSetting(commonSettings, _settings, key, value); _addIntSetting(commonSettings, _settings, key, value);
} else if (key == "EvictionUseAccessedTime") { } else if (key == 'EvictionUseAccessedTime') {
_addBooleanSetting(commonSettings, _settings, key, value); _addBooleanSetting(commonSettings, _settings, key, value);
} else if (key == "MaxCacheSizeBytes") { } else if (key == 'MaxCacheSizeBytes') {
_addIntSetting(commonSettings, _settings, key, value); _addIntSetting(commonSettings, _settings, key, value);
} else if (key == "MaxUploadCount") { } else if (key == 'MaxUploadCount') {
_addIntSetting(commonSettings, _settings, key, value); _addIntSetting(commonSettings, _settings, key, value);
} else if (key == "OnlineCheckRetrySeconds") { } else if (key == 'OnlineCheckRetrySeconds') {
_addIntSetting(commonSettings, _settings, key, value); _addIntSetting(commonSettings, _settings, key, value);
} else if (key == "PreferredDownloadType") { } else if (key == 'PreferredDownloadType') {
_addListSetting(commonSettings, _settings, key, value, [ _addListSetting(commonSettings, _settings, key, value, [
"default", 'default',
"direct", 'direct',
"ring_buffer", 'ring_buffer',
], Icons.download); ], Icons.download);
} else if (key == "RetryReadCount") { } else if (key == 'RetryReadCount') {
_addIntSetting(commonSettings, _settings, key, value); _addIntSetting(commonSettings, _settings, key, value);
} else if (key == "RingBufferFileSize") { } else if (key == 'RingBufferFileSize') {
_addIntListSetting( _addIntListSetting(
commonSettings, commonSettings,
_settings, _settings,
key, key,
value, value,
["128", "256", "512", "1024", "2048"], ['128', '256', '512', '1024', '2048'],
512, 512,
Icons.animation, Icons.animation,
); );
} else if (key == "EncryptConfig") { } else if (key == 'EncryptConfig') {
value.forEach((subKey, subValue) { value.forEach((subKey, subValue) {
if (subKey == "EncryptionToken") { if (subKey == 'EncryptionToken') {
_addPasswordSetting( _addPasswordSetting(
encryptConfigSettings, encryptConfigSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "Path") { } else if (subKey == 'Path') {
_addStringSetting( _addStringSetting(
encryptConfigSettings, encryptConfigSettings,
_settings[key], _settings[key],
@ -273,9 +273,9 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
); );
} }
}); });
} else if (key == "HostConfig") { } else if (key == 'HostConfig') {
value.forEach((subKey, subValue) { value.forEach((subKey, subValue) {
if (subKey == "AgentString") { if (subKey == 'AgentString') {
_addStringSetting( _addStringSetting(
hostConfigSettings, hostConfigSettings,
_settings[key], _settings[key],
@ -283,21 +283,21 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
subValue, subValue,
Icons.support_agent, Icons.support_agent,
); );
} else if (subKey == "ApiPassword") { } else if (subKey == 'ApiPassword') {
_addPasswordSetting( _addPasswordSetting(
hostConfigSettings, hostConfigSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "ApiPort") { } else if (subKey == 'ApiPort') {
_addIntSetting( _addIntSetting(
hostConfigSettings, hostConfigSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "ApiUser") { } else if (subKey == 'ApiUser') {
_addStringSetting( _addStringSetting(
hostConfigSettings, hostConfigSettings,
_settings[key], _settings[key],
@ -305,7 +305,7 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
subValue, subValue,
Icons.person, Icons.person,
); );
} else if (subKey == "HostNameOrIp") { } else if (subKey == 'HostNameOrIp') {
_addStringSetting( _addStringSetting(
hostConfigSettings, hostConfigSettings,
_settings[key], _settings[key],
@ -313,7 +313,7 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
subValue, subValue,
Icons.computer, Icons.computer,
); );
} else if (subKey == "Path") { } else if (subKey == 'Path') {
_addStringSetting( _addStringSetting(
hostConfigSettings, hostConfigSettings,
_settings[key], _settings[key],
@ -321,16 +321,16 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
subValue, subValue,
Icons.route, Icons.route,
); );
} else if (subKey == "Protocol") { } else if (subKey == 'Protocol') {
_addListSetting( _addListSetting(
hostConfigSettings, hostConfigSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
["http", "https"], ['http', 'https'],
Icons.http, Icons.http,
); );
} else if (subKey == "TimeoutMs") { } else if (subKey == 'TimeoutMs') {
_addIntSetting( _addIntSetting(
hostConfigSettings, hostConfigSettings,
_settings[key], _settings[key],
@ -339,23 +339,23 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
); );
} }
}); });
} else if (key == "RemoteConfig") { } else if (key == 'RemoteConfig') {
value.forEach((subKey, subValue) { value.forEach((subKey, subValue) {
if (subKey == "ApiPort") { if (subKey == 'ApiPort') {
_addIntSetting( _addIntSetting(
remoteConfigSettings, remoteConfigSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "EncryptionToken") { } else if (subKey == 'EncryptionToken') {
_addPasswordSetting( _addPasswordSetting(
remoteConfigSettings, remoteConfigSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "HostNameOrIp") { } else if (subKey == 'HostNameOrIp') {
_addStringSetting( _addStringSetting(
remoteConfigSettings, remoteConfigSettings,
_settings[key], _settings[key],
@ -363,21 +363,21 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
subValue, subValue,
Icons.computer, Icons.computer,
); );
} else if (subKey == "MaxConnections") { } else if (subKey == 'MaxConnections') {
_addIntSetting( _addIntSetting(
remoteConfigSettings, remoteConfigSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "ReceiveTimeoutMs") { } else if (subKey == 'ReceiveTimeoutMs') {
_addIntSetting( _addIntSetting(
remoteConfigSettings, remoteConfigSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "SendTimeoutMs") { } else if (subKey == 'SendTimeoutMs') {
_addIntSetting( _addIntSetting(
remoteConfigSettings, remoteConfigSettings,
_settings[key], _settings[key],
@ -386,27 +386,27 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
); );
} }
}); });
} else if (key == "RemoteMount") { } else if (key == 'RemoteMount') {
value.forEach((subKey, subValue) { value.forEach((subKey, subValue) {
if (subKey == "Enable") { if (subKey == 'Enable') {
List<SettingsTile> tempSettings = []; List<SettingsTile> tempSettings = [];
_addBooleanSetting(tempSettings, _settings[key], subKey, subValue); _addBooleanSetting(tempSettings, _settings[key], subKey, subValue);
remoteMountSettings.insertAll(0, tempSettings); remoteMountSettings.insertAll(0, tempSettings);
} else if (subKey == "ApiPort") { } else if (subKey == 'ApiPort') {
_addIntSetting( _addIntSetting(
remoteMountSettings, remoteMountSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "ClientPoolSize") { } else if (subKey == 'ClientPoolSize') {
_addIntSetting( _addIntSetting(
remoteMountSettings, remoteMountSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "EncryptionToken") { } else if (subKey == 'EncryptionToken') {
_addPasswordSetting( _addPasswordSetting(
remoteMountSettings, remoteMountSettings,
_settings[key], _settings[key],
@ -415,16 +415,16 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
); );
} }
}); });
} else if (key == "S3Config") { } else if (key == 'S3Config') {
value.forEach((subKey, subValue) { value.forEach((subKey, subValue) {
if (subKey == "AccessKey") { if (subKey == 'AccessKey') {
_addPasswordSetting( _addPasswordSetting(
s3ConfigSettings, s3ConfigSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "Bucket") { } else if (subKey == 'Bucket') {
_addStringSetting( _addStringSetting(
s3ConfigSettings, s3ConfigSettings,
_settings[key], _settings[key],
@ -432,14 +432,14 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
subValue, subValue,
Icons.folder, Icons.folder,
); );
} else if (subKey == "EncryptionToken") { } else if (subKey == 'EncryptionToken') {
_addPasswordSetting( _addPasswordSetting(
s3ConfigSettings, s3ConfigSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "Region") { } else if (subKey == 'Region') {
_addStringSetting( _addStringSetting(
s3ConfigSettings, s3ConfigSettings,
_settings[key], _settings[key],
@ -447,16 +447,16 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
subValue, subValue,
Icons.map, Icons.map,
); );
} else if (subKey == "SecretKey") { } else if (subKey == 'SecretKey') {
_addPasswordSetting( _addPasswordSetting(
s3ConfigSettings, s3ConfigSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "TimeoutMs") { } else if (subKey == 'TimeoutMs') {
_addIntSetting(s3ConfigSettings, _settings[key], subKey, subValue); _addIntSetting(s3ConfigSettings, _settings[key], subKey, subValue);
} else if (subKey == "URL") { } else if (subKey == 'URL') {
_addStringSetting( _addStringSetting(
s3ConfigSettings, s3ConfigSettings,
_settings[key], _settings[key],
@ -464,14 +464,14 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
subValue, subValue,
Icons.http, Icons.http,
); );
} else if (subKey == "UsePathStyle") { } else if (subKey == 'UsePathStyle') {
_addBooleanSetting( _addBooleanSetting(
s3ConfigSettings, s3ConfigSettings,
_settings[key], _settings[key],
subKey, subKey,
subValue, subValue,
); );
} else if (subKey == "UseRegionInURL") { } else if (subKey == 'UseRegionInURL') {
_addBooleanSetting( _addBooleanSetting(
s3ConfigSettings, s3ConfigSettings,
_settings[key], _settings[key],
@ -480,9 +480,9 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
); );
} }
}); });
} else if (key == "SiaConfig") { } else if (key == 'SiaConfig') {
value.forEach((subKey, subValue) { value.forEach((subKey, subValue) {
if (subKey == "Bucket") { if (subKey == 'Bucket') {
_addStringSetting( _addStringSetting(
siaConfigSettings, siaConfigSettings,
_settings[key], _settings[key],
@ -527,7 +527,7 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
SettingsSection( SettingsSection(
title: const Text('Remote Mount'), title: const Text('Remote Mount'),
tiles: tiles:
_settings["RemoteMount"]["Enable"] as bool _settings['RemoteMount']['Enable'] as bool
? remoteMountSettings ? remoteMountSettings
: [remoteMountSettings[0]], : [remoteMountSettings[0]],
), ),
@ -565,4 +565,13 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
_settings = jsonDecode(jsonEncode(widget.mount.mountConfig.settings)); _settings = jsonDecode(jsonEncode(widget.mount.mountConfig.settings));
super.initState(); super.initState();
} }
@override
void setState(VoidCallback fn) {
if (!mounted) {
return;
}
super.setState(fn);
}
} }

View File

@ -109,4 +109,13 @@ class _MountWidgetState extends State<MountWidget> {
Provider.of<Mount>(context, listen: false).refresh(); Provider.of<Mount>(context, listen: false).refresh();
}); });
} }
@override
void setState(VoidCallback fn) {
if (!mounted) {
return;
}
super.setState(fn);
}
} }