This commit is contained in:
parent
0ffa461f91
commit
242109cfe5
@ -28,6 +28,45 @@
|
|||||||
#include "utils/unix.hpp"
|
#include "utils/unix.hpp"
|
||||||
#include "utils/windows.hpp"
|
#include "utils/windows.hpp"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
[[nodiscard]] auto from_json(const nlohmann::json &json)
|
||||||
|
-> std::unordered_map<repertory::provider_type,
|
||||||
|
std::unordered_map<std::string, std::string>> {
|
||||||
|
std::unordered_map<repertory::provider_type,
|
||||||
|
std::unordered_map<std::string, std::string>>
|
||||||
|
map_of_maps{
|
||||||
|
{repertory::provider_type::encrypt, {}},
|
||||||
|
{repertory::provider_type::remote, {}},
|
||||||
|
{repertory::provider_type::s3, {}},
|
||||||
|
{repertory::provider_type::sia, {}},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const auto &[prov, map] : map_of_maps) {
|
||||||
|
for (const auto &[key, value] :
|
||||||
|
json[repertory::provider_type_to_string(prov)].items()) {
|
||||||
|
if (value.is_null()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
map_of_maps[prov][key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return map_of_maps;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto to_json(const auto &map_of_maps) -> nlohmann::json {
|
||||||
|
nlohmann::json json;
|
||||||
|
for (const auto &[prov, map] : map_of_maps) {
|
||||||
|
for (const auto &[key, value] : map) {
|
||||||
|
json[repertory::provider_type_to_string(prov)][key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
namespace repertory::ui {
|
namespace repertory::ui {
|
||||||
mgmt_app_config::mgmt_app_config() {
|
mgmt_app_config::mgmt_app_config() {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
@ -41,7 +80,7 @@ mgmt_app_config::mgmt_app_config() {
|
|||||||
api_auth_ = data.at(JSON_API_AUTH).get<std::string>();
|
api_auth_ = data.at(JSON_API_AUTH).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_ = data.at(JSON_MOUNT_LOCATIONS).get<decltype(locations_)>();
|
locations_ = from_json(data.at(JSON_MOUNT_LOCATIONS));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +124,7 @@ void mgmt_app_config::save() const {
|
|||||||
data[JSON_API_AUTH] = api_auth_;
|
data[JSON_API_AUTH] = 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] = locations_;
|
data[JSON_MOUNT_LOCATIONS] = to_json(locations_);
|
||||||
if (utils::file::write_json_file(config_file, data)) {
|
if (utils::file::write_json_file(config_file, data)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -100,6 +139,10 @@ void mgmt_app_config::save() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mgmt_app_config::set_api_port(std::uint16_t api_port) {
|
void mgmt_app_config::set_api_port(std::uint16_t api_port) {
|
||||||
|
if (api_port_ == api_port) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
api_port_ = api_port;
|
api_port_ = api_port;
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
@ -108,6 +151,10 @@ void mgmt_app_config::set_mount_location(provider_type prov,
|
|||||||
std::string_view name,
|
std::string_view name,
|
||||||
std::string_view location) {
|
std::string_view location) {
|
||||||
recur_mutex_lock lock(mtx_);
|
recur_mutex_lock lock(mtx_);
|
||||||
|
if (locations_[prov][std::string{name}] == std::string{location}) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
locations_[prov][std::string{name}] = std::string{location};
|
locations_[prov][std::string{name}] = std::string{location};
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user