mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-18 11:49:30 +08:00
43 lines
997 B
C++
43 lines
997 B
C++
#ifndef SERVER_HPP
|
|
#define SERVER_HPP
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <httplib.h>
|
|
#include <vector>
|
|
#include <thread>
|
|
#include <filesystem>
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
class UpdateServer : protected httplib::Server {
|
|
using ArchName = std::string;
|
|
using FileName = std::string;
|
|
using FileData = std::vector<char>;
|
|
using FileHash = std::string;
|
|
struct FileInfo {
|
|
FileData data;
|
|
FileHash hash;
|
|
};
|
|
public:
|
|
UpdateServer();
|
|
~UpdateServer() override = default;
|
|
|
|
UpdateServer& start(int port = 7541, const std::string& admin_key = "");
|
|
void join();
|
|
|
|
static UpdateServer& Instance();
|
|
|
|
private:
|
|
void update_files();
|
|
static FileHash hash_file(const FileData& data);
|
|
bool is_file_exists(const std::string& arch, const std::string& file) const;
|
|
|
|
std::string m_admin_key;
|
|
std::thread m_server_thread;
|
|
fs::path m_assets_dir;
|
|
std::map<ArchName, std::map<FileName, FileInfo>> m_files;
|
|
};
|
|
|
|
#endif //SERVER_HPP
|