mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 13:39:25 +08:00
ref: change reload key to admin key
This commit is contained in:
@@ -28,12 +28,12 @@ int main(int argc, char* argv[]) {
|
||||
cxxopts::Options options("BlCrackUpdater");
|
||||
options.add_options()
|
||||
("p,port", "Port to listen on", cxxopts::value<int>()->default_value("7541"))
|
||||
("k,reload-key", "Reload key for the server", cxxopts::value<std::string>()->default_value("BlCrackUpdater"));
|
||||
("k,admin-key", "Admin key for the server", cxxopts::value<std::string>()->default_value("BlCrackUpdater"));
|
||||
auto result = options.parse(argc, argv);
|
||||
|
||||
int port = result["port"].as<int>();
|
||||
std::string reload_key = result["reload-key"].as<std::string>();
|
||||
std::string admin_key = result["admin-key"].as<std::string>();
|
||||
|
||||
UpdateServer::Instance().start(port, reload_key).join();
|
||||
UpdateServer::Instance().start(port, admin_key).join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -77,20 +77,20 @@ UpdateServer::UpdateServer() {
|
||||
|
||||
Post("/reload", [this](const httplib::Request& req, httplib::Response& res) {
|
||||
SPDLOG_INFO("{} requested reload", req.remote_addr);
|
||||
if (req.body == m_reload_key) {
|
||||
if (req.body == m_admin_key) {
|
||||
update_files();
|
||||
res.status = 200;
|
||||
return;
|
||||
}
|
||||
SPDLOG_WARN("Invalid reload key: {}", req.body);
|
||||
SPDLOG_WARN("Invalid key: {}", req.body);
|
||||
res.status = 400;
|
||||
});
|
||||
}
|
||||
|
||||
UpdateServer& UpdateServer::start(int port, const std::string& reload_key) {
|
||||
m_reload_key = reload_key;
|
||||
UpdateServer& UpdateServer::start(int port, const std::string& admin_key) {
|
||||
m_admin_key = admin_key;
|
||||
m_server_thread = std::thread([this, port] {
|
||||
SPDLOG_INFO("Update server on port {}, reload key: {}", port, m_reload_key);
|
||||
SPDLOG_INFO("Update server on port {}, reload key: {}", port, m_admin_key);
|
||||
listen("0.0.0.0", port);
|
||||
});
|
||||
return *this;
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
UpdateServer();
|
||||
~UpdateServer() override = default;
|
||||
|
||||
UpdateServer& start(int port = 7541, const std::string& reload_key = "");
|
||||
UpdateServer& start(int port = 7541, const std::string& admin_key = "");
|
||||
void join();
|
||||
|
||||
static UpdateServer& Instance();
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
static FileHash hash_file(const FileData& data);
|
||||
bool is_file_exists(const std::string& arch, const std::string& file) const;
|
||||
|
||||
std::string m_reload_key;
|
||||
std::string m_admin_key;
|
||||
std::thread m_server_thread;
|
||||
std::map<ArchName, std::map<FileName, FileInfo>> m_files;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user