test: Add 1 and update 10 files
This commit is contained in:
@@ -196,9 +196,9 @@ void PutHandler::handle_upload_object(const drogon::HttpRequestPtr& req, std::fu
|
||||
// Ensure the temporary file is removed even if errors occur
|
||||
ScopeFileDeleter temp_file_deleter(temp_path);
|
||||
|
||||
// Calculate hash
|
||||
uint64_t hash = hash_file(temp_path.string());
|
||||
if (hash == 0) {
|
||||
// Calculate SHA-256 hash
|
||||
std::string hash = hash_file(temp_path.string());
|
||||
if (hash.empty()) {
|
||||
resp->setStatusCode(drogon::k500InternalServerError);
|
||||
nlohmann::json response = {{"result", "error"}, {"error", "Failed to calculate hash"}};
|
||||
resp->setBody(response.dump());
|
||||
@@ -215,8 +215,8 @@ void PutHandler::handle_upload_object(const drogon::HttpRequestPtr& req, std::fu
|
||||
metadata["tgz_content_hash"] = get_hash_from_tgz(temp_path.string());
|
||||
}
|
||||
|
||||
// Move file to final location
|
||||
std::filesystem::path final_path = server_.config_.object_store_path / std::to_string(hash);
|
||||
// Move file to final location (using SHA-256 hash as filename)
|
||||
std::filesystem::path final_path = server_.config_.object_store_path / hash;
|
||||
|
||||
if (!std::filesystem::exists(final_path)) {
|
||||
try {
|
||||
@@ -235,7 +235,7 @@ void PutHandler::handle_upload_object(const drogon::HttpRequestPtr& req, std::fu
|
||||
|
||||
// Update database index
|
||||
dbEntry entry;
|
||||
entry.hash = std::to_string(hash);
|
||||
entry.hash = hash;
|
||||
entry.labeltags = metadata["labeltags"].get<std::vector<std::string>>();
|
||||
entry.metadata = metadata;
|
||||
|
||||
@@ -250,7 +250,7 @@ void PutHandler::handle_upload_object(const drogon::HttpRequestPtr& req, std::fu
|
||||
return;
|
||||
}
|
||||
|
||||
resp->setBody(nlohmann::json({{"result", "success"}, {"hash", std::to_string(hash)}}).dump());
|
||||
resp->setBody(nlohmann::json({{"result", "success"}, {"hash", hash}}).dump());
|
||||
resp->setContentTypeCode(drogon::CT_APPLICATION_JSON);
|
||||
callback(resp);
|
||||
}
|
||||
|
Reference in New Issue
Block a user