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