Compare commits

..

No commits in common. "ce1a3c416ccbdee51d2f7cbe3699b1220388fe8e" and "06ad2a62cbfe0de8799e0d39ea1a6d5f08237e4e" have entirely different histories.

6 changed files with 66 additions and 191 deletions

View File

@ -24,7 +24,6 @@
#include "types/repertory.hpp"
#include "ui/handlers.hpp"
#include "ui/mgmt_app_config.hpp"
#include "utils/cli_utils.hpp"
#include "utils/file.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;
}
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);
return exit_code::success;

View File

@ -25,7 +25,17 @@
#include "events/consumers/console_consumer.hpp"
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 {
public:
@ -42,7 +52,6 @@ public:
private:
mgmt_app_config *config_;
std::string repertory_binary_;
httplib::Server *server_;
private:
@ -53,16 +62,15 @@ private:
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_post_mount(auto &&req, auto &&res) const;
void handle_put_set_value_by_name(auto &&req, auto &&res);
auto read_process(provider_type prov, std::string_view name,
std::string_view command) const -> std::vector<std::string>;
static auto read_process(provider_type prov, std::string_view name,
std::string_view command)
-> std::vector<std::string>;
};
} // namespace repertory::ui

View File

@ -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_

View File

@ -25,7 +25,6 @@
#include "events/event_system.hpp"
#include "rpc/common.hpp"
#include "types/repertory.hpp"
#include "ui/mgmt_app_config.hpp"
#include "utils/error_utils.hpp"
#include "utils/file.hpp"
#include "utils/path.hpp"
@ -33,13 +32,7 @@
namespace repertory::ui {
handlers::handlers(mgmt_app_config *config, httplib::Server *server)
: config_(config),
#if defined(_WIN32)
repertory_binary_(utils::path::combine(".", {"repertory.exe"})),
#else // !defined(_WIN32)
repertory_binary_(utils::path::combine(".", {"repertory"})),
#endif // defined(_WIN32)
server_(server) {
: config_(config), server_(server) {
REPERTORY_USES_FUNCTION_NAME();
server_->set_pre_routing_handler(
@ -81,10 +74,6 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
server->Get("/api/v1/mount",
[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) {
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 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") {
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;
}
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 {
REPERTORY_USES_FUNCTION_NAME();
auto name = req.get_param_value("name");
auto prov = provider_type_from_string(req.get_param_value("type"));
auto type = req.get_param_value("type");
auto prov = provider_type_from_string(type);
auto status_name = app_config::get_provider_display_name(prov);
auto name = req.get_param_value("name");
switch (prov) {
case provider_type::encrypt:
@ -230,61 +206,55 @@ void handlers::handle_get_mount_status(auto &&req, auto &&res) const {
break;
default:
throw utils::error::create_exception(function_name,
{
"provider is not supported",
provider_type_to_string(prov),
name,
});
throw utils::error::create_exception(
function_name, {
fmt::format("`{}` is not supported", name),
});
}
auto lines = launch_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 lines = handlers::read_process(prov, name, "-status");
auto result =
nlohmann::json::parse(utils::string::join(lines, '\n')).at(status_name);
res.set_content(result.dump(), "application/json");
res.status = http_error_codes::ok;
}
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 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 prov = provider_type_from_string(type);
if (unmount) {
launch_process(prov, name, "-unmount");
read_process(prov, name, "-unmount");
} else {
launch_process(prov, name, fmt::format(R"("{}")", location), true);
read_process(prov, name, fmt::format("\"{}\"", location));
}
res.status = http_error_codes::ok;
}
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 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");
#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)
launch_process(prov, name, fmt::format("-set {} '{}'", key, value));
read_process(prov, name, fmt::format("-set {} '{}'", key, value));
#endif // defined(_WIN32)
res.status = http_error_codes::ok;
}
auto handlers::launch_process(provider_type prov, std::string_view name,
std::string_view command, bool background) const
auto handlers::read_process(provider_type prov, std::string_view name,
std::string_view command)
-> std::vector<std::string> {
REPERTORY_USES_FUNCTION_NAME();
@ -308,29 +278,17 @@ auto handlers::launch_process(provider_type prov, std::string_view name,
break;
default:
throw utils::error::create_exception(function_name,
{
"provider is not supported",
provider_type_to_string(prov),
name,
});
throw utils::error::create_exception(
function_name, {
fmt::format("`{}` is not supported", name),
});
}
auto cmd_line =
fmt::format(R"({} {} {})", repertory_binary_, str_type, command);
if (background) {
return "";
}
auto cmd_line = fmt::format("repertory {} {}", str_type, command);
auto *pipe = popen(cmd_line.c_str(), "r");
if (pipe == nullptr) {
throw utils::error::create_exception(function_name,
{
"failed to execute command",
provider_type_to_string(prov),
name,
});
return {};
}
std::string data;

View File

@ -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

View File

@ -34,23 +34,26 @@ class _MountWidgetState extends State<MountWidget> {
);
return ListTile(
isThreeLine: true,
isThreeLine: isActive,
leading: IconButton(
icon: Icon(Icons.settings, color: textColor),
onPressed: () {
Navigator.pushNamed(context, '/settings', arguments: mount);
},
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
nameText,
SelectableText(
mount.path,
style: TextStyle(color: subTextColor),
),
],
),
subtitle:
isActive
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
nameText,
SelectableText(
mount.path,
style: TextStyle(color: subTextColor),
),
],
)
: nameText,
title: SelectableText(
initialCaps(mount.type),
style: TextStyle(color: textColor, fontWeight: FontWeight.bold),
@ -68,8 +71,8 @@ class _MountWidgetState extends State<MountWidget> {
_enabled = false;
});
String? location = mount.path;
if (!isActive && mount.path.isEmpty) {
String? location;
if (!isActive) {
location = await mount.getMountLocation();
if (location == null) {}
}