reset on error
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2025-03-15 13:17:54 -05:00
parent 532dd3c417
commit 196d721005
7 changed files with 99 additions and 13 deletions

View File

@ -50,6 +50,10 @@ private:
mutable std::mutex mtx_;
private:
[[nodiscard]] static auto data_directory_exists(provider_type prov,
std::string_view name)
-> bool;
void handle_get_mount(auto &&req, auto &&res) const;
void handle_get_mount_list(auto &&res) const;

View File

@ -150,22 +150,28 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
handlers::~handlers() { event_system::instance().stop(); }
void handlers::set_key_value(provider_type prov, std::string_view name,
std::string_view key,
std::string_view value) const {
#if defined(_WIN32)
launch_process(prov, name, fmt::format(R"(-set {} "{}")", key, value));
#else // !defined(_WIN32)
launch_process(prov, name, fmt::format("-set {} '{}'", key, value));
#endif // defined(_WIN32)
auto handlers::data_directory_exists(provider_type prov, std::string_view name)
-> bool {
auto data_dir = utils::path::combine(app_config::get_root_data_directory(),
{
app_config::get_provider_name(prov),
name,
});
return utils::file::directory{data_dir}.exists();
}
void handlers::handle_get_mount(auto &&req, auto &&res) const {
REPERTORY_USES_FUNCTION_NAME();
auto prov = provider_type_from_string(req.get_param_value("type"));
auto name = req.get_param_value("name");
auto lines = launch_process(prov, req.get_param_value("name"), "-dc");
if (not data_directory_exists(prov, name)) {
res.status = http_error_codes::not_found;
return;
}
auto lines = launch_process(prov, name, "-dc");
if (lines.at(0U) != "0") {
throw utils::error::create_exception(function_name, {
@ -214,6 +220,11 @@ void handlers::handle_get_mount_location(auto &&req, auto &&res) const {
auto name = req.get_param_value("name");
auto prov = provider_type_from_string(req.get_param_value("type"));
if (not data_directory_exists(prov, name)) {
res.status = http_error_codes::not_found;
return;
}
res.set_content(
nlohmann::json({
{"Location", config_->get_mount_location(prov, name)},
@ -229,6 +240,11 @@ void handlers::handle_get_mount_status(auto &&req, auto &&res) const {
auto name = req.get_param_value("name");
auto prov = provider_type_from_string(req.get_param_value("type"));
if (not data_directory_exists(prov, name)) {
res.status = http_error_codes::not_found;
return;
}
auto status_name = app_config::get_provider_display_name(prov);
switch (prov) {
@ -288,9 +304,15 @@ void handlers::handle_post_add_mount(auto &&req, auto &&res) const {
}
void handlers::handle_post_mount(auto &&req, auto &&res) const {
auto location = utils::path::absolute(req.get_param_value("location"));
auto name = req.get_param_value("name");
auto prov = provider_type_from_string(req.get_param_value("type"));
if (not data_directory_exists(prov, name)) {
res.status = http_error_codes::not_found;
return;
}
auto location = utils::path::absolute(req.get_param_value("location"));
auto unmount = utils::string::to_bool(req.get_param_value("unmount"));
if (unmount) {
@ -303,9 +325,15 @@ void handlers::handle_post_mount(auto &&req, auto &&res) const {
}
void handlers::handle_put_set_value_by_name(auto &&req, auto &&res) const {
auto key = req.get_param_value("key");
auto name = req.get_param_value("name");
auto prov = provider_type_from_string(req.get_param_value("type"));
if (not data_directory_exists(prov, name)) {
res.status = http_error_codes::not_found;
return;
}
auto key = req.get_param_value("key");
auto value = req.get_param_value("value");
set_key_value(prov, name, key, value);
@ -389,4 +417,14 @@ auto handlers::launch_process(provider_type prov, std::string_view name,
return utils::string::split(utils::string::replace(data, "\r", ""), '\n',
false);
}
void handlers::set_key_value(provider_type prov, std::string_view name,
std::string_view key,
std::string_view value) const {
#if defined(_WIN32)
launch_process(prov, name, fmt::format(R"(-set {} "{}")", key, value));
#else // !defined(_WIN32)
launch_process(prov, name, fmt::format("-set {} '{}'", key, value));
#endif // defined(_WIN32)
}
} // namespace repertory::ui

View File

@ -1,3 +1,5 @@
import 'package:flutter/material.dart' show GlobalKey, NavigatorState;
const addMountTitle = 'New Mount Settings';
const appTitle = 'Repertory Management Portal';
const databaseTypeList = ['rocksdb', 'sqlite'];
@ -7,3 +9,5 @@ const padding = 15.0;
const protocolTypeList = ['http', 'https'];
const providerTypeList = ['Encrypt', 'Remote', 'S3', 'Sia'];
const ringBufferSizeList = ['128', '256', '512', '1024', '2048'];
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

View File

@ -30,6 +30,7 @@ class _MyAppState extends State<MyApp> {
);
return MaterialApp(
navigatorKey: constants.navigatorKey,
themeMode: ThemeMode.dark,
darkTheme: ThemeData(
useMaterial3: true,

View File

@ -3,11 +3,13 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:repertory/helpers.dart';
import 'package:repertory/models/mount_list.dart';
import 'package:repertory/types/mount_config.dart';
class Mount with ChangeNotifier {
final MountConfig mountConfig;
Mount(this.mountConfig, {isAdd = false}) {
final MountList? _mountList;
Mount(this.mountConfig, this._mountList, {isAdd = false}) {
if (isAdd) {
return;
}
@ -28,6 +30,11 @@ class Mount with ChangeNotifier {
),
);
if (response.statusCode == 404) {
_mountList?.reset();
return;
}
if (response.statusCode != 200) {
return;
}
@ -50,6 +57,11 @@ class Mount with ChangeNotifier {
),
);
if (response.statusCode == 404) {
_mountList?.reset();
return;
}
if (response.statusCode != 200) {
return;
}
@ -108,6 +120,11 @@ class Mount with ChangeNotifier {
),
);
if (response.statusCode == 404) {
_mountList?.reset();
return null;
}
if (response.statusCode != 200) {
return null;
}

View File

@ -2,7 +2,9 @@ import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' show ModalRoute;
import 'package:http/http.dart' as http;
import 'package:repertory/constants.dart' as constants;
import 'package:repertory/helpers.dart';
import 'package:repertory/models/mount.dart';
import 'package:repertory/types/mount_config.dart';
@ -48,15 +50,21 @@ class MountList with ChangeNotifier {
Uri.parse('${getBaseUri()}/api/v1/mount_list'),
);
if (response.statusCode == 404) {
reset();
return;
}
if (response.statusCode != 200) {
return;
}
List<Mount> nextList = [];
jsonDecode(response.body).forEach((type, value) {
nextList.addAll(
value
.map((name) => Mount(MountConfig(type: type, name: name)))
.map((name) => Mount(MountConfig(type: type, name: name), this))
.toList(),
);
});
@ -100,6 +108,19 @@ class MountList with ChangeNotifier {
return _fetch();
}
Future<void> reset() async {
_mountList = [];
notifyListeners();
_fetch();
if (constants.navigatorKey.currentContext == null ||
ModalRoute.of(constants.navigatorKey.currentContext!)?.settings.name !=
'/') {
constants.navigatorKey.currentState?.pushReplacementNamed('/');
}
}
void remove(String name) {
_mountList.removeWhere((item) => item.name == name);

View File

@ -219,6 +219,7 @@ class _AddMountScreenState extends State<AddMountScreen> {
settings: _settings[mountType],
type: mountType,
),
null,
isAdd: true,
);
});