reset on error
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
parent
532dd3c417
commit
196d721005
@ -50,6 +50,10 @@ private:
|
|||||||
mutable std::mutex mtx_;
|
mutable std::mutex mtx_;
|
||||||
|
|
||||||
private:
|
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(auto &&req, auto &&res) const;
|
||||||
|
|
||||||
void handle_get_mount_list(auto &&res) const;
|
void handle_get_mount_list(auto &&res) const;
|
||||||
|
@ -150,22 +150,28 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
|||||||
|
|
||||||
handlers::~handlers() { event_system::instance().stop(); }
|
handlers::~handlers() { event_system::instance().stop(); }
|
||||||
|
|
||||||
void handlers::set_key_value(provider_type prov, std::string_view name,
|
auto handlers::data_directory_exists(provider_type prov, std::string_view name)
|
||||||
std::string_view key,
|
-> bool {
|
||||||
std::string_view value) const {
|
auto data_dir = utils::path::combine(app_config::get_root_data_directory(),
|
||||||
#if defined(_WIN32)
|
{
|
||||||
launch_process(prov, name, fmt::format(R"(-set {} "{}")", key, value));
|
app_config::get_provider_name(prov),
|
||||||
#else // !defined(_WIN32)
|
name,
|
||||||
launch_process(prov, name, fmt::format("-set {} '{}'", key, value));
|
});
|
||||||
#endif // defined(_WIN32)
|
return utils::file::directory{data_dir}.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handlers::handle_get_mount(auto &&req, auto &&res) const {
|
void handlers::handle_get_mount(auto &&req, auto &&res) const {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
auto prov = provider_type_from_string(req.get_param_value("type"));
|
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") {
|
if (lines.at(0U) != "0") {
|
||||||
throw utils::error::create_exception(function_name, {
|
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 name = req.get_param_value("name");
|
||||||
auto prov = provider_type_from_string(req.get_param_value("type"));
|
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(
|
res.set_content(
|
||||||
nlohmann::json({
|
nlohmann::json({
|
||||||
{"Location", config_->get_mount_location(prov, name)},
|
{"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 name = req.get_param_value("name");
|
||||||
auto prov = provider_type_from_string(req.get_param_value("type"));
|
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);
|
auto status_name = app_config::get_provider_display_name(prov);
|
||||||
|
|
||||||
switch (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 {
|
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 name = req.get_param_value("name");
|
||||||
auto prov = provider_type_from_string(req.get_param_value("type"));
|
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"));
|
auto unmount = utils::string::to_bool(req.get_param_value("unmount"));
|
||||||
|
|
||||||
if (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 {
|
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 name = req.get_param_value("name");
|
||||||
auto prov = provider_type_from_string(req.get_param_value("type"));
|
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");
|
auto value = req.get_param_value("value");
|
||||||
|
|
||||||
set_key_value(prov, name, key, 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',
|
return utils::string::split(utils::string::replace(data, "\r", ""), '\n',
|
||||||
false);
|
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
|
} // namespace repertory::ui
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'package:flutter/material.dart' show GlobalKey, NavigatorState;
|
||||||
|
|
||||||
const addMountTitle = 'New Mount Settings';
|
const addMountTitle = 'New Mount Settings';
|
||||||
const appTitle = 'Repertory Management Portal';
|
const appTitle = 'Repertory Management Portal';
|
||||||
const databaseTypeList = ['rocksdb', 'sqlite'];
|
const databaseTypeList = ['rocksdb', 'sqlite'];
|
||||||
@ -7,3 +9,5 @@ const padding = 15.0;
|
|||||||
const protocolTypeList = ['http', 'https'];
|
const protocolTypeList = ['http', 'https'];
|
||||||
const providerTypeList = ['Encrypt', 'Remote', 'S3', 'Sia'];
|
const providerTypeList = ['Encrypt', 'Remote', 'S3', 'Sia'];
|
||||||
const ringBufferSizeList = ['128', '256', '512', '1024', '2048'];
|
const ringBufferSizeList = ['128', '256', '512', '1024', '2048'];
|
||||||
|
|
||||||
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||||
|
@ -30,6 +30,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
|
navigatorKey: constants.navigatorKey,
|
||||||
themeMode: ThemeMode.dark,
|
themeMode: ThemeMode.dark,
|
||||||
darkTheme: ThemeData(
|
darkTheme: ThemeData(
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
|
@ -3,11 +3,13 @@ import 'dart:convert';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:repertory/helpers.dart';
|
import 'package:repertory/helpers.dart';
|
||||||
|
import 'package:repertory/models/mount_list.dart';
|
||||||
import 'package:repertory/types/mount_config.dart';
|
import 'package:repertory/types/mount_config.dart';
|
||||||
|
|
||||||
class Mount with ChangeNotifier {
|
class Mount with ChangeNotifier {
|
||||||
final MountConfig mountConfig;
|
final MountConfig mountConfig;
|
||||||
Mount(this.mountConfig, {isAdd = false}) {
|
final MountList? _mountList;
|
||||||
|
Mount(this.mountConfig, this._mountList, {isAdd = false}) {
|
||||||
if (isAdd) {
|
if (isAdd) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -28,6 +30,11 @@ class Mount with ChangeNotifier {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 404) {
|
||||||
|
_mountList?.reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -50,6 +57,11 @@ class Mount with ChangeNotifier {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 404) {
|
||||||
|
_mountList?.reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -108,6 +120,11 @@ class Mount with ChangeNotifier {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 404) {
|
||||||
|
_mountList?.reset();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,9 @@ import 'dart:convert';
|
|||||||
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart' show ModalRoute;
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
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/types/mount_config.dart';
|
import 'package:repertory/types/mount_config.dart';
|
||||||
@ -48,15 +50,21 @@ class MountList with ChangeNotifier {
|
|||||||
Uri.parse('${getBaseUri()}/api/v1/mount_list'),
|
Uri.parse('${getBaseUri()}/api/v1/mount_list'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 404) {
|
||||||
|
reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Mount> nextList = [];
|
List<Mount> nextList = [];
|
||||||
|
|
||||||
jsonDecode(response.body).forEach((type, value) {
|
jsonDecode(response.body).forEach((type, value) {
|
||||||
nextList.addAll(
|
nextList.addAll(
|
||||||
value
|
value
|
||||||
.map((name) => Mount(MountConfig(type: type, name: name)))
|
.map((name) => Mount(MountConfig(type: type, name: name), this))
|
||||||
.toList(),
|
.toList(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -100,6 +108,19 @@ class MountList with ChangeNotifier {
|
|||||||
return _fetch();
|
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) {
|
void remove(String name) {
|
||||||
_mountList.removeWhere((item) => item.name == name);
|
_mountList.removeWhere((item) => item.name == name);
|
||||||
|
|
||||||
|
@ -219,6 +219,7 @@ class _AddMountScreenState extends State<AddMountScreen> {
|
|||||||
settings: _settings[mountType],
|
settings: _settings[mountType],
|
||||||
type: mountType,
|
type: mountType,
|
||||||
),
|
),
|
||||||
|
null,
|
||||||
isAdd: true,
|
isAdd: true,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user