Bug fixing

This commit is contained in:
Your Name
2025-05-25 13:07:03 +12:00
parent 21d079f285
commit 7b3706ebf5
5 changed files with 68 additions and 65 deletions

View File

@@ -67,18 +67,28 @@ void PutHandler::handle_put_object(const httplib::Request& req, httplib::Respons
}
// Validate required metadata fields
if (!metadata.contains("labels") || !metadata["labels"].is_array() || metadata["labels"].empty()) {
if (!metadata.contains("labeltags") || !metadata["labeltags"].is_array() || metadata["labeltags"].empty()) {
res.status = 400;
nlohmann::json response = {{"result", "error"}, {"error", "Missing or invalid required metadata field: labels (must be non-empty array)"}};
nlohmann::json response = {{"result", "error"}, {"error", "Missing or invalid required metadata field: labeltags (must be non-empty array of label:tag pairs)"}};
res.set_content(response.dump(), "application/json");
return;
}
if (!metadata.contains("tags") || !metadata["tags"].is_array() || metadata["tags"].empty()) {
res.status = 400;
nlohmann::json response = {{"result", "error"}, {"error", "Missing or invalid required metadata field: tags (must be non-empty array)"}};
res.set_content(response.dump(), "application/json");
return;
// Validate each label:tag pair format
for (const auto& label_tag : metadata["labeltags"]) {
if (!label_tag.is_string()) {
res.status = 400;
nlohmann::json response = {{"result", "error"}, {"error", "Invalid label:tag pair format - must be a string"}};
res.set_content(response.dump(), "application/json");
return;
}
std::string pair = label_tag.get<std::string>();
if (pair.find(':') == std::string::npos) {
res.status = 400;
nlohmann::json response = {{"result", "error"}, {"error", "Invalid label:tag pair format - must contain ':' separator"}};
res.set_content(response.dump(), "application/json");
return;
}
}
// Add filename to metadata if not provided
@@ -155,8 +165,7 @@ void PutHandler::handle_put_object(const httplib::Request& req, httplib::Respons
// Update database index
dbEntry entry;
entry.hash = std::to_string(hash);
entry.labels = metadata["labels"].get<std::vector<std::string>>();
entry.tags = metadata["tags"].get<std::vector<std::string>>();
entry.label_tags = metadata["labeltags"].get<std::vector<std::string>>();
entry.metadata = metadata;
if (!server_.db_->update_or_insert(entry)) {