This commit is contained in:
Your Name
2025-04-30 22:04:50 +12:00
parent aa234ebef5
commit 9c0ade961f
4 changed files with 10625 additions and 193 deletions

View File

@@ -2,6 +2,7 @@
#define SERVER_HPP
#include "config.hpp"
#include "httplib.hpp"
#include <string>
#include <unordered_map>
#include <memory>
@@ -25,20 +26,17 @@ private:
uint64_t hash;
};
void handle_connection(int client_socket);
void handle_get_object(int client_socket, const std::string& path);
void handle_get_hash(int client_socket, const std::string& path);
void handle_get_directory(int client_socket);
void handle_put_object(int client_socket, const std::string& token, const std::string& label_tag);
void send_response(int client_socket, int status_code, const std::string& content_type, const std::string& body);
void send_file(int client_socket, const std::filesystem::path& file_path);
void setup_routes();
void handle_get_object(const httplib::Request& req, httplib::Response& res);
void handle_get_hash(const httplib::Request& req, httplib::Response& res);
void handle_get_directory(const httplib::Request& req, httplib::Response& res);
void handle_put_object(const httplib::Request& req, httplib::Response& res);
bool validate_write_token(const std::string& token) const;
std::pair<std::string, std::string> parse_label_tag(const std::string& label_tag) const;
const ServerConfig& config_;
int server_socket_;
httplib::Server server_;
std::atomic<bool> running_;
std::unordered_map<uint64_t, ObjectInfo> object_index_;
std::unordered_map<std::string, uint64_t> label_tag_index_;
};