Compare commits
No commits in common. "ce1a3c416ccbdee51d2f7cbe3699b1220388fe8e" and "06ad2a62cbfe0de8799e0d39ea1a6d5f08237e4e" have entirely different histories.
ce1a3c416c
...
06ad2a62cb
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "types/repertory.hpp"
|
#include "types/repertory.hpp"
|
||||||
#include "ui/handlers.hpp"
|
#include "ui/handlers.hpp"
|
||||||
#include "ui/mgmt_app_config.hpp"
|
|
||||||
#include "utils/cli_utils.hpp"
|
#include "utils/cli_utils.hpp"
|
||||||
#include "utils/file.hpp"
|
#include "utils/file.hpp"
|
||||||
#include "utils/string.hpp"
|
#include "utils/string.hpp"
|
||||||
@ -52,7 +51,11 @@ ui(std::vector<const char *> args, const std::string & /*data_directory*/,
|
|||||||
return exit_code::ui_mount_failed;
|
return exit_code::ui_mount_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui::mgmt_app_config config{};
|
ui::mgmt_app_config config{
|
||||||
|
.api_auth_ = "test",
|
||||||
|
.api_port_ = ui_port,
|
||||||
|
.api_user_ = "test",
|
||||||
|
};
|
||||||
ui::handlers handlers(&config, &server);
|
ui::handlers handlers(&config, &server);
|
||||||
|
|
||||||
return exit_code::success;
|
return exit_code::success;
|
||||||
|
@ -25,7 +25,17 @@
|
|||||||
#include "events/consumers/console_consumer.hpp"
|
#include "events/consumers/console_consumer.hpp"
|
||||||
|
|
||||||
namespace repertory::ui {
|
namespace repertory::ui {
|
||||||
class mgmt_app_config;
|
struct mgmt_app_config final {
|
||||||
|
std::string api_auth_{"test"};
|
||||||
|
std::uint16_t api_port_{default_ui_mgmt_port};
|
||||||
|
std::string api_user_{"test"};
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_api_auth() const -> std::string { return api_auth_; }
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_api_port() const -> std::uint16_t { return api_port_; }
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_api_user() const -> std::string { return api_user_; }
|
||||||
|
};
|
||||||
|
|
||||||
class handlers final {
|
class handlers final {
|
||||||
public:
|
public:
|
||||||
@ -42,7 +52,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
mgmt_app_config *config_;
|
mgmt_app_config *config_;
|
||||||
std::string repertory_binary_;
|
|
||||||
httplib::Server *server_;
|
httplib::Server *server_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -53,16 +62,15 @@ private:
|
|||||||
|
|
||||||
void handle_get_mount_list(auto &&res) const;
|
void handle_get_mount_list(auto &&res) const;
|
||||||
|
|
||||||
void handle_get_mount_location(auto &&req, auto &&res) const;
|
|
||||||
|
|
||||||
void handle_get_mount_status(auto &&req, auto &&res) const;
|
void handle_get_mount_status(auto &&req, auto &&res) const;
|
||||||
|
|
||||||
void handle_post_mount(auto &&req, auto &&res) const;
|
void handle_post_mount(auto &&req, auto &&res) const;
|
||||||
|
|
||||||
void handle_put_set_value_by_name(auto &&req, auto &&res);
|
void handle_put_set_value_by_name(auto &&req, auto &&res);
|
||||||
|
|
||||||
auto read_process(provider_type prov, std::string_view name,
|
static auto read_process(provider_type prov, std::string_view name,
|
||||||
std::string_view command) const -> std::vector<std::string>;
|
std::string_view command)
|
||||||
|
-> std::vector<std::string>;
|
||||||
};
|
};
|
||||||
} // namespace repertory::ui
|
} // namespace repertory::ui
|
||||||
|
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
#ifndef REPERTORY_INCLUDE_UI_MGMT_APP_CONFIG_HPP_
|
|
||||||
#define REPERTORY_INCLUDE_UI_MGMT_APP_CONFIG_HPP_
|
|
||||||
|
|
||||||
#include "types/repertory.hpp"
|
|
||||||
|
|
||||||
namespace repertory::ui {
|
|
||||||
class mgmt_app_config final {
|
|
||||||
private:
|
|
||||||
std::string api_auth_{"test"};
|
|
||||||
std::uint16_t api_port_{default_ui_mgmt_port};
|
|
||||||
std::string api_user_{"test"};
|
|
||||||
std::unordered_map<provider_type,
|
|
||||||
std::unordered_map<std::string, std::string>>
|
|
||||||
locations_;
|
|
||||||
mutable std::recursive_mutex mtx_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
[[nodiscard]] auto get_api_auth() const -> std::string { return api_auth_; }
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_api_port() const -> std::uint16_t { return api_port_; }
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_api_user() const -> std::string { return api_user_; }
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_mount_location(provider_type prov,
|
|
||||||
std::string_view name) const
|
|
||||||
-> std::string;
|
|
||||||
|
|
||||||
void set_mount_location(provider_type prov, std::string_view name,
|
|
||||||
std::string_view location);
|
|
||||||
};
|
|
||||||
} // namespace repertory::ui
|
|
||||||
|
|
||||||
#endif // REPERTORY_INCLUDE_UI_MGMT_APP_CONFIG_HPP_
|
|
@ -25,7 +25,6 @@
|
|||||||
#include "events/event_system.hpp"
|
#include "events/event_system.hpp"
|
||||||
#include "rpc/common.hpp"
|
#include "rpc/common.hpp"
|
||||||
#include "types/repertory.hpp"
|
#include "types/repertory.hpp"
|
||||||
#include "ui/mgmt_app_config.hpp"
|
|
||||||
#include "utils/error_utils.hpp"
|
#include "utils/error_utils.hpp"
|
||||||
#include "utils/file.hpp"
|
#include "utils/file.hpp"
|
||||||
#include "utils/path.hpp"
|
#include "utils/path.hpp"
|
||||||
@ -33,13 +32,7 @@
|
|||||||
|
|
||||||
namespace repertory::ui {
|
namespace repertory::ui {
|
||||||
handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
||||||
: config_(config),
|
: config_(config), server_(server) {
|
||||||
#if defined(_WIN32)
|
|
||||||
repertory_binary_(utils::path::combine(".", {"repertory.exe"})),
|
|
||||||
#else // !defined(_WIN32)
|
|
||||||
repertory_binary_(utils::path::combine(".", {"repertory"})),
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
server_(server) {
|
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
server_->set_pre_routing_handler(
|
server_->set_pre_routing_handler(
|
||||||
@ -81,10 +74,6 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
|||||||
server->Get("/api/v1/mount",
|
server->Get("/api/v1/mount",
|
||||||
[this](auto &&req, auto &&res) { handle_get_mount(req, res); });
|
[this](auto &&req, auto &&res) { handle_get_mount(req, res); });
|
||||||
|
|
||||||
server->Get("/api/v1/mount_location", [this](auto &&req, auto &&res) {
|
|
||||||
handle_get_mount_location(req, res);
|
|
||||||
});
|
|
||||||
|
|
||||||
server->Get("/api/v1/mount_list", [this](auto && /* req */, auto &&res) {
|
server->Get("/api/v1/mount_list", [this](auto && /* req */, auto &&res) {
|
||||||
handle_get_mount_list(res);
|
handle_get_mount_list(res);
|
||||||
});
|
});
|
||||||
@ -144,7 +133,7 @@ void handlers::handle_get_mount(auto &&req, auto &&res) const {
|
|||||||
|
|
||||||
auto prov = provider_type_from_string(req.get_param_value("type"));
|
auto prov = provider_type_from_string(req.get_param_value("type"));
|
||||||
|
|
||||||
auto lines = launch_process(prov, req.get_param_value("name"), "-dc");
|
auto lines = handlers::read_process(prov, req.get_param_value("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, {
|
||||||
@ -194,26 +183,13 @@ void handlers::handle_get_mount_list(auto &&res) const {
|
|||||||
res.status = http_error_codes::ok;
|
res.status = http_error_codes::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
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"));
|
|
||||||
|
|
||||||
res.set_content(
|
|
||||||
nlohmann::json({
|
|
||||||
{"Location", config_->get_mount_location(prov, name)},
|
|
||||||
})
|
|
||||||
.dump(),
|
|
||||||
"application/json");
|
|
||||||
res.status = http_error_codes::ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
void handlers::handle_get_mount_status(auto &&req, auto &&res) const {
|
void handlers::handle_get_mount_status(auto &&req, auto &&res) const {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
auto name = req.get_param_value("name");
|
auto type = req.get_param_value("type");
|
||||||
auto prov = provider_type_from_string(req.get_param_value("type"));
|
auto prov = provider_type_from_string(type);
|
||||||
|
|
||||||
auto status_name = app_config::get_provider_display_name(prov);
|
auto status_name = app_config::get_provider_display_name(prov);
|
||||||
|
auto name = req.get_param_value("name");
|
||||||
|
|
||||||
switch (prov) {
|
switch (prov) {
|
||||||
case provider_type::encrypt:
|
case provider_type::encrypt:
|
||||||
@ -230,61 +206,55 @@ void handlers::handle_get_mount_status(auto &&req, auto &&res) const {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw utils::error::create_exception(function_name,
|
throw utils::error::create_exception(
|
||||||
{
|
function_name, {
|
||||||
"provider is not supported",
|
fmt::format("`{}` is not supported", name),
|
||||||
provider_type_to_string(prov),
|
|
||||||
name,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lines = launch_process(prov, name, "-status");
|
auto lines = handlers::read_process(prov, name, "-status");
|
||||||
|
|
||||||
nlohmann::json result(
|
|
||||||
nlohmann::json::parse(utils::string::join(lines, '\n')).at(status_name));
|
|
||||||
if (result.at("Location").get<std::string>().empty()) {
|
|
||||||
result.at("Location") = config_->get_mount_location(prov, name);
|
|
||||||
} else if (result.at("Active").get<bool>()) {
|
|
||||||
config_->set_mount_location(prov, name,
|
|
||||||
result.at("Location").get<std::string>());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
auto result =
|
||||||
|
nlohmann::json::parse(utils::string::join(lines, '\n')).at(status_name);
|
||||||
res.set_content(result.dump(), "application/json");
|
res.set_content(result.dump(), "application/json");
|
||||||
res.status = http_error_codes::ok;
|
res.status = http_error_codes::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 type = req.get_param_value("type");
|
||||||
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 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"));
|
||||||
|
auto prov = provider_type_from_string(type);
|
||||||
|
|
||||||
if (unmount) {
|
if (unmount) {
|
||||||
launch_process(prov, name, "-unmount");
|
read_process(prov, name, "-unmount");
|
||||||
} else {
|
} else {
|
||||||
launch_process(prov, name, fmt::format(R"("{}")", location), true);
|
read_process(prov, name, fmt::format("\"{}\"", location));
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status = http_error_codes::ok;
|
res.status = http_error_codes::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handlers::handle_put_set_value_by_name(auto &&req, auto &&res) {
|
void handlers::handle_put_set_value_by_name(auto &&req, auto &&res) {
|
||||||
auto key = req.get_param_value("key");
|
auto type = req.get_param_value("type");
|
||||||
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(type);
|
||||||
|
|
||||||
|
auto key = req.get_param_value("key");
|
||||||
auto value = req.get_param_value("value");
|
auto value = req.get_param_value("value");
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
launch_process(prov, name, fmt::format(R"(-set {} "{}")", key, value));
|
read_process(prov, name, fmt::format("-set {} \"{}\"", key, value));
|
||||||
#else //! defined(_WIN32)
|
#else //! defined(_WIN32)
|
||||||
launch_process(prov, name, fmt::format("-set {} '{}'", key, value));
|
read_process(prov, name, fmt::format("-set {} '{}'", key, value));
|
||||||
#endif // defined(_WIN32)
|
#endif // defined(_WIN32)
|
||||||
|
|
||||||
res.status = http_error_codes::ok;
|
res.status = http_error_codes::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto handlers::launch_process(provider_type prov, std::string_view name,
|
auto handlers::read_process(provider_type prov, std::string_view name,
|
||||||
std::string_view command, bool background) const
|
std::string_view command)
|
||||||
-> std::vector<std::string> {
|
-> std::vector<std::string> {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
@ -308,29 +278,17 @@ auto handlers::launch_process(provider_type prov, std::string_view name,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw utils::error::create_exception(function_name,
|
throw utils::error::create_exception(
|
||||||
{
|
function_name, {
|
||||||
"provider is not supported",
|
fmt::format("`{}` is not supported", name),
|
||||||
provider_type_to_string(prov),
|
|
||||||
name,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cmd_line =
|
auto cmd_line = fmt::format("repertory {} {}", str_type, command);
|
||||||
fmt::format(R"({} {} {})", repertory_binary_, str_type, command);
|
|
||||||
|
|
||||||
if (background) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
auto *pipe = popen(cmd_line.c_str(), "r");
|
auto *pipe = popen(cmd_line.c_str(), "r");
|
||||||
if (pipe == nullptr) {
|
if (pipe == nullptr) {
|
||||||
throw utils::error::create_exception(function_name,
|
return {};
|
||||||
{
|
|
||||||
"failed to execute command",
|
|
||||||
provider_type_to_string(prov),
|
|
||||||
name,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string data;
|
std::string data;
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
#include "ui/mgmt_app_config.hpp"
|
|
||||||
|
|
||||||
namespace repertory::ui {
|
|
||||||
auto mgmt_app_config::get_mount_location(provider_type prov,
|
|
||||||
std::string_view name) const
|
|
||||||
-> std::string {
|
|
||||||
recur_mutex_lock lock(mtx_);
|
|
||||||
if (locations_.contains(prov) &&
|
|
||||||
locations_.at(prov).contains(std::string{name})) {
|
|
||||||
return locations_.at(prov).at(std::string{name});
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
void mgmt_app_config::set_mount_location(provider_type prov,
|
|
||||||
std::string_view name,
|
|
||||||
std::string_view location) {
|
|
||||||
recur_mutex_lock lock(mtx_);
|
|
||||||
locations_[prov][std::string{name}] = std::string{location};
|
|
||||||
}
|
|
||||||
} // namespace repertory::ui
|
|
@ -34,14 +34,16 @@ class _MountWidgetState extends State<MountWidget> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
isThreeLine: true,
|
isThreeLine: isActive,
|
||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
icon: Icon(Icons.settings, color: textColor),
|
icon: Icon(Icons.settings, color: textColor),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pushNamed(context, '/settings', arguments: mount);
|
Navigator.pushNamed(context, '/settings', arguments: mount);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
subtitle: Column(
|
subtitle:
|
||||||
|
isActive
|
||||||
|
? Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
nameText,
|
nameText,
|
||||||
@ -50,7 +52,8 @@ class _MountWidgetState extends State<MountWidget> {
|
|||||||
style: TextStyle(color: subTextColor),
|
style: TextStyle(color: subTextColor),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
)
|
||||||
|
: nameText,
|
||||||
title: SelectableText(
|
title: SelectableText(
|
||||||
initialCaps(mount.type),
|
initialCaps(mount.type),
|
||||||
style: TextStyle(color: textColor, fontWeight: FontWeight.bold),
|
style: TextStyle(color: textColor, fontWeight: FontWeight.bold),
|
||||||
@ -68,8 +71,8 @@ class _MountWidgetState extends State<MountWidget> {
|
|||||||
_enabled = false;
|
_enabled = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
String? location = mount.path;
|
String? location;
|
||||||
if (!isActive && mount.path.isEmpty) {
|
if (!isActive) {
|
||||||
location = await mount.getMountLocation();
|
location = await mount.getMountLocation();
|
||||||
if (location == null) {}
|
if (location == null) {}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user