Antonio SJ Musumeci 2 weeks ago
parent
commit
76dd6582e5
  1. 78
      src/mergerfs_webui.cpp
  2. 10
      src/mergerfs_webui.hpp

78
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></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<std::string,std::string> 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;
}

10
src/mergerfs_webui.hpp

@ -0,0 +1,10 @@
#pragma once
namespace mergerfs
{
namespace webui
{
int main(const int argc,
char **argv);
}
}
Loading…
Cancel
Save