config: Add 1 and update 10 files
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 1m33s
Build-Test-Publish / build (linux/arm64) (push) Successful in 2m45s
Build-Test-Publish / create-manifest (push) Successful in 13s

This commit is contained in:
j842
2025-08-16 13:08:05 +12:00
parent baa215e762
commit 38a3a7a478
11 changed files with 156 additions and 35 deletions

View File

@@ -10,6 +10,7 @@
#include <sstream>
#include "server.hpp"
#include "logger.hpp"
#include "hash.hpp"
#include "compress.hpp"
#include "string_utils.hpp" // Include the new utility header
@@ -34,7 +35,7 @@ bool Server::init_db() {
db_ = std::make_unique<Database>(db_path);
return true;
} catch (const std::runtime_error& e) {
std::cerr << "Database initialization error: " << e.what() << std::endl;
LOG_ERROR("Database initialization error: {}", e.what());
return false;
}
}
@@ -114,7 +115,7 @@ Server::Server(const ServerConfig& config)
Server::setInstance(this);
if (!std::filesystem::exists(config_.object_store_path)) {
std::cerr << "Object store directory does not exist: " << config_.object_store_path << std::endl;
LOG_ERROR("Object store directory does not exist: {}", config_.object_store_path.string());
return;
}
@@ -146,7 +147,7 @@ Server::~Server() {
bool Server::start() {
if (!db_) { // Check if DB initialization failed
std::cerr << "Database is not initialized. Cannot start server." << std::endl;
LOG_ERROR("Database is not initialized. Cannot start server.");
return false;
}
setup_routes();
@@ -167,7 +168,7 @@ bool Server::start() {
drogon::app().run();
} catch (const std::exception& e) {
running_ = false;
std::cerr << "Failed to start server: " << e.what() << std::endl;
LOG_ERROR("Failed to start server: {}", e.what());
return false;
}
return true;
@@ -177,7 +178,7 @@ void Server::stop() {
if (running_) {
drogon::app().quit();
running_ = false;
std::cout << "Server stopped." << std::endl;
LOG_INFO("Server stopped.");
}
}
@@ -379,7 +380,7 @@ void Server::handle_get_metadata(const drogon::HttpRequestPtr& req, std::functio
response = {{"result", "success"}, {"metadata", entry.metadata}};
resp->setBody(response.dump());
} catch (const nlohmann::json::exception& e) {
std::cerr << "Error serializing metadata for hash " << hash_str << ": " << e.what() << std::endl;
LOG_ERROR("Error serializing metadata for hash {}: {}", hash_str, e.what());
resp->setStatusCode(drogon::k500InternalServerError);
response = {{"result", "error"}, {"error", "Internal server error: Failed to serialize metadata"}};
resp->setBody(response.dump());
@@ -455,7 +456,7 @@ void Server::handle_delete_object(const drogon::HttpRequestPtr& req, std::functi
try {
std::filesystem::remove(file_path);
} catch (const std::filesystem::filesystem_error& e) {
std::cerr << "Error deleting object file: " << e.what() << std::endl;
LOG_ERROR("Error deleting object file: {}", e.what());
resp->setStatusCode(drogon::k500InternalServerError);
nlohmann::json response = {{"result", "error"}, {"error", "Failed to delete object file: " + std::string(e.what())}};
resp->setBody(response.dump());