Bug fixing
This commit is contained in:
@@ -67,9 +67,9 @@ void PutHandler::handle_put_object(const httplib::Request& req, httplib::Respons
|
||||
}
|
||||
|
||||
// Validate required metadata fields
|
||||
if (!metadata.contains("label")) {
|
||||
if (!metadata.contains("labels") || !metadata["labels"].is_array() || metadata["labels"].empty()) {
|
||||
res.status = 400;
|
||||
nlohmann::json response = {{"result", "error"}, {"error", "Missing required metadata field: label"}};
|
||||
nlohmann::json response = {{"result", "error"}, {"error", "Missing or invalid required metadata field: labels (must be non-empty array)"}};
|
||||
res.set_content(response.dump(), "application/json");
|
||||
return;
|
||||
}
|
||||
@@ -81,15 +81,6 @@ void PutHandler::handle_put_object(const httplib::Request& req, httplib::Respons
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract label and tags
|
||||
std::string label = metadata["label"];
|
||||
if (label.empty()) {
|
||||
res.status = 400;
|
||||
nlohmann::json response = {{"result", "error"}, {"error", "Label cannot be empty"}};
|
||||
res.set_content(response.dump(), "application/json");
|
||||
return;
|
||||
}
|
||||
|
||||
// Add filename to metadata if not provided
|
||||
if (!metadata.contains("filename")) {
|
||||
metadata["filename"] = file.filename;
|
||||
@@ -147,6 +138,7 @@ void PutHandler::handle_put_object(const httplib::Request& req, httplib::Respons
|
||||
|
||||
// Move file to final location
|
||||
std::filesystem::path final_path = server_.config_.object_store_path / std::to_string(hash);
|
||||
|
||||
if (!std::filesystem::exists(final_path)) {
|
||||
try {
|
||||
std::filesystem::rename(temp_path, final_path);
|
||||
@@ -163,22 +155,11 @@ void PutHandler::handle_put_object(const httplib::Request& req, httplib::Respons
|
||||
// Update database index
|
||||
dbEntry entry;
|
||||
entry.hash = std::to_string(hash);
|
||||
entry.metadata = metadata; // Store the complete metadata
|
||||
entry.labels = metadata["labels"].get<std::vector<std::string>>();
|
||||
entry.tags = metadata["tags"].get<std::vector<std::string>>();
|
||||
entry.metadata = metadata;
|
||||
|
||||
// For each tag, create a label:tag entry
|
||||
bool success = true;
|
||||
for (const auto& tag : metadata["tags"]) {
|
||||
std::string tag_str = tag.get<std::string>();
|
||||
if (tag_str.empty()) continue; // Skip empty tags
|
||||
|
||||
entry.label_tag = label + ":" + tag_str;
|
||||
if (!server_.db_->update_or_insert(entry)) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
if (!server_.db_->update_or_insert(entry)) {
|
||||
res.status = 500;
|
||||
nlohmann::json response = {{"result", "error"}, {"error", "Failed to update database index"}};
|
||||
res.set_content(response.dump(), "application/json");
|
||||
|
Reference in New Issue
Block a user