Tidyin g
This commit is contained in:
@@ -186,21 +186,12 @@ void Server::setup_routes() {
|
||||
handle_get_metadata(req, res);
|
||||
});
|
||||
|
||||
// Delete a label/tag (object remains)
|
||||
server_.Get("/deletetag", [this](const httplib::Request& req, httplib::Response& res) {
|
||||
handle_delete_tag(req, res);
|
||||
});
|
||||
|
||||
// Delete an object (and all tags on that object)
|
||||
server_.Get("/deleteobject", [this](const httplib::Request& req, httplib::Response& res) {
|
||||
handle_delete_object(req, res);
|
||||
});
|
||||
|
||||
// Add a tag to an existing object
|
||||
server_.Get("/appendtag", [this](const httplib::Request& req, httplib::Response& res) {
|
||||
handle_append_tag(req, res);
|
||||
});
|
||||
|
||||
server_.Get("/status", [this](const httplib::Request& req, httplib::Response& res) {
|
||||
res.set_content(nlohmann::json({{"result", "success"}, {"status", "ok"}}).dump(), "application/json");
|
||||
});
|
||||
@@ -486,33 +477,6 @@ void Server::add_file_metadata(const std::string &file_path, nlohmann::json &met
|
||||
metadata["file_modification_time"] = std::chrono::system_clock::to_time_t(sctp);
|
||||
}
|
||||
|
||||
void Server::handle_delete_tag(const httplib::Request& req, httplib::Response& res) {
|
||||
std::map<std::string, std::string> params;
|
||||
if (!validate_write_request(req, res, {"token", "labeltag"}, params)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate label:tag format
|
||||
auto [label, tag] = parse_label_tag(params["labeltag"]);
|
||||
if (label.empty() || tag.empty()) {
|
||||
res.status = 400;
|
||||
nlohmann::json response = {{"result", "error"}, {"error", "Invalid label:tag format"}};
|
||||
res.set_content(response.dump(), "application/json");
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete the label:tag from the database
|
||||
if (!db_->remove(params["labeltag"])) {
|
||||
res.status = 404;
|
||||
nlohmann::json response = {{"result", "error"}, {"error", "Label:tag not found or deletion failed"}};
|
||||
res.set_content(response.dump(), "application/json");
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json response = {{"result", "success"}};
|
||||
res.set_content(response.dump(), "application/json");
|
||||
}
|
||||
|
||||
void Server::handle_delete_object(const httplib::Request& req, httplib::Response& res) {
|
||||
std::map<std::string, std::string> params;
|
||||
if (!validate_write_request(req, res, {"token", "hash"}, params)) {
|
||||
@@ -551,57 +515,6 @@ void Server::handle_delete_object(const httplib::Request& req, httplib::Response
|
||||
res.set_content(response.dump(), "application/json");
|
||||
}
|
||||
|
||||
void Server::handle_append_tag(const httplib::Request& req, httplib::Response& res) {
|
||||
std::map<std::string, std::string> params;
|
||||
if (!validate_write_request(req, res, {"token", "labeltag", "hash"}, params)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate label:tag format
|
||||
auto [label, tag] = parse_label_tag(params["labeltag"]);
|
||||
if (label.empty() || tag.empty()) {
|
||||
res.status = 400;
|
||||
nlohmann::json response = {{"result", "error"}, {"error", "Invalid label:tag format"}};
|
||||
res.set_content(response.dump(), "application/json");
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate that the hash exists as a file
|
||||
std::filesystem::path file_path = config_.object_store_path / params["hash"];
|
||||
if (!std::filesystem::exists(file_path) || !std::filesystem::is_regular_file(file_path)) {
|
||||
res.status = 404;
|
||||
nlohmann::json response = {{"result", "error"}, {"error", "Object not found for hash: " + params["hash"]}};
|
||||
res.set_content(response.dump(), "application/json");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the label:tag already exists
|
||||
dbEntry existing_entry;
|
||||
if (db_->get(params["labeltag"], existing_entry)) {
|
||||
if (existing_entry.hash == params["hash"]) {
|
||||
// Label:tag already points to this hash, nothing to do
|
||||
nlohmann::json response = {{"result", "success"}, {"message", "Label:tag already points to this hash"}};
|
||||
res.set_content(response.dump(), "application/json");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new entry with the label:tag pointing to the hash
|
||||
dbEntry entry;
|
||||
entry.label_tag = params["labeltag"];
|
||||
entry.hash = params["hash"];
|
||||
entry.metadata = nlohmann::json({}); // Empty metadata for appended tags
|
||||
|
||||
if (!db_->update_or_insert(entry)) {
|
||||
res.status = 500;
|
||||
nlohmann::json response = {{"result", "error"}, {"error", "Failed to append tag"}};
|
||||
res.set_content(response.dump(), "application/json");
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json response = {{"result", "success"}};
|
||||
res.set_content(response.dump(), "application/json");
|
||||
}
|
||||
|
||||
void Server::handle_exists(const httplib::Request& req, httplib::Response& res) {
|
||||
const auto& key = req.matches[1].str();
|
||||
|
Reference in New Issue
Block a user