This commit is contained in:
@ -21,12 +21,14 @@
|
||||
*/
|
||||
#include "ui/handlers.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "rpc/common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/base64.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include <spdlog/fmt/bundled/base.h>
|
||||
|
||||
namespace repertory::ui {
|
||||
handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
||||
@ -69,6 +71,42 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
||||
res.status = http_error_codes::internal_error;
|
||||
});
|
||||
|
||||
server->Get("/api/v1/mount_list", [](auto && /* req */, auto &&res) {
|
||||
auto data_dir =
|
||||
utils::file::directory{app_config::get_root_data_directory()};
|
||||
|
||||
nlohmann::json result;
|
||||
|
||||
auto encrypt_dir = data_dir.get_directory("encrypt");
|
||||
if (encrypt_dir && encrypt_dir->get_file("config.json")) {
|
||||
result["encrypt"].emplace_back("encrypt");
|
||||
}
|
||||
|
||||
const auto process_dir = [&data_dir, &result](std::string_view name) {
|
||||
auto name_dir = data_dir.get_directory(name);
|
||||
if (not name_dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &dir : name_dir->get_directories()) {
|
||||
if (not dir->get_file("config.json")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result[name].emplace_back(
|
||||
utils::path::strip_to_file_name(dir->get_path()));
|
||||
}
|
||||
};
|
||||
|
||||
process_dir("remote");
|
||||
process_dir("s3");
|
||||
process_dir("sia");
|
||||
|
||||
fmt::println("{}", result.dump());
|
||||
res.set_content(result.dump(), "application/json");
|
||||
res.status = http_error_codes::ok;
|
||||
});
|
||||
|
||||
event_system::instance().start();
|
||||
|
||||
static std::atomic<httplib::Server *> this_server{server_};
|
||||
|
Reference in New Issue
Block a user