From 76c15fc874980da39c77a65cd5f9cd94d552db14 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Fri, 2 Jan 2026 00:27:45 -0600 Subject: [PATCH] checkpoint --- src/mergerfs_webui.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++ src/mergerfs_webui.hpp | 10 ++++++ 2 files changed, 88 insertions(+) create mode 100644 src/mergerfs_webui.cpp create mode 100644 src/mergerfs_webui.hpp diff --git a/src/mergerfs_webui.cpp b/src/mergerfs_webui.cpp new file mode 100644 index 00000000..4aa69d71 --- /dev/null +++ b/src/mergerfs_webui.cpp @@ -0,0 +1,78 @@ +#include "mergerfs_webui.hpp" + +#include "mergerfs_api.hpp" +#include "fs_mounts.hpp" + +#include "httplib.h" +#include "json.hpp" + +using json = nlohmann::json; + +static +void +_serve_root(const httplib::Request &req_, + httplib::Response &res_) +{ + std::string html = R"html()html"; + + res_.set_content(html, + "text/html"); +} + +static +void +_serve_mounts(const httplib::Request &req_, + httplib::Response &res_) +{ + json j; + fs::MountVec mounts; + + fs::mounts(mounts); + + j = json::array(); + for(const auto &mount : mounts) + { + if(mount.type != "fuse.mergerfs") + continue; + j.push_back(mount.dir); + } + + res_.set_content(j.dump(), + "application/json"); +} + +static +void +_serve_kvs(const httplib::Request &req_, + httplib::Response &res_) +{ + json j; + std::map kvs; + + mergerfs::api::get_kvs("/mnt/tmp/mergerfs",&kvs); + + j = kvs; + + res_.set_content(j.dump(), + "application/json"); +} + +int +mergerfs::webui::main(const int argc_, + char **argv_) +{ + httplib::Server http_server; + std::string host; + int port; + + host = "0.0.0.0"; + port = 8000; + + http_server.Get("/",::_serve_root); + http_server.Get("/mounts",::_serve_mounts); + http_server.Get("/kvs",::_serve_kvs); + + http_server.listen(host,port); + + return 0; +} diff --git a/src/mergerfs_webui.hpp b/src/mergerfs_webui.hpp new file mode 100644 index 00000000..47066ea3 --- /dev/null +++ b/src/mergerfs_webui.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace mergerfs +{ + namespace webui + { + int main(const int argc, + char **argv); + } +}