portal configuration
This commit is contained in:
parent
b513ef7545
commit
083406a85d
@ -42,6 +42,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
mgmt_app_config *config_;
|
mgmt_app_config *config_;
|
||||||
|
std::string repertory_binary_;
|
||||||
httplib::Server *server_;
|
httplib::Server *server_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -60,9 +61,8 @@ private:
|
|||||||
|
|
||||||
void handle_put_set_value_by_name(auto &&req, auto &&res);
|
void handle_put_set_value_by_name(auto &&req, auto &&res);
|
||||||
|
|
||||||
static auto read_process(provider_type prov, std::string_view name,
|
auto read_process(provider_type prov, std::string_view name,
|
||||||
std::string_view command)
|
std::string_view command) const -> std::vector<std::string>;
|
||||||
-> std::vector<std::string>;
|
|
||||||
};
|
};
|
||||||
} // namespace repertory::ui
|
} // namespace repertory::ui
|
||||||
|
|
||||||
|
@ -33,7 +33,13 @@
|
|||||||
|
|
||||||
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), 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) {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
server_->set_pre_routing_handler(
|
server_->set_pre_routing_handler(
|
||||||
@ -232,10 +238,9 @@ void handlers::handle_get_mount_status(auto &&req, auto &&res) const {
|
|||||||
|
|
||||||
auto lines = handlers::read_process(prov, name, "-status");
|
auto lines = handlers::read_process(prov, name, "-status");
|
||||||
|
|
||||||
nlohmann::json result{
|
nlohmann::json result(
|
||||||
nlohmann::json::parse(utils::string::join(lines, '\n')).at(status_name),
|
nlohmann::json::parse(utils::string::join(lines, '\n')).at(status_name));
|
||||||
};
|
if (result["Location"].get<std::string>().empty()) {
|
||||||
if (result["Location"].empty()) {
|
|
||||||
result["Location"] = config_->get_mount_location(prov, name);
|
result["Location"] = config_->get_mount_location(prov, name);
|
||||||
} else {
|
} else {
|
||||||
config_->set_mount_location(prov, name,
|
config_->set_mount_location(prov, name,
|
||||||
@ -280,7 +285,7 @@ void handlers::handle_put_set_value_by_name(auto &&req, auto &&res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto handlers::read_process(provider_type prov, std::string_view name,
|
auto handlers::read_process(provider_type prov, std::string_view name,
|
||||||
std::string_view command)
|
std::string_view command) const
|
||||||
-> std::vector<std::string> {
|
-> std::vector<std::string> {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
@ -304,17 +309,25 @@ auto handlers::read_process(provider_type prov, std::string_view name,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw utils::error::create_exception(
|
throw utils::error::create_exception(function_name,
|
||||||
function_name, {
|
{
|
||||||
fmt::format("`{}` is not supported", name),
|
"provider is not supported",
|
||||||
});
|
provider_type_to_string(prov),
|
||||||
|
name,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cmd_line = fmt::format("repertory {} {}", str_type, command);
|
auto cmd_line =
|
||||||
|
fmt::format(R"("{}" {} {})", repertory_binary_, str_type, command);
|
||||||
|
|
||||||
auto *pipe = popen(cmd_line.c_str(), "r");
|
auto *pipe = popen(cmd_line.c_str(), "r");
|
||||||
if (pipe == nullptr) {
|
if (pipe == nullptr) {
|
||||||
return {};
|
throw utils::error::create_exception(function_name,
|
||||||
|
{
|
||||||
|
"failed to execute command",
|
||||||
|
provider_type_to_string(prov),
|
||||||
|
name,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string data;
|
std::string data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user