feat: Update 2 files

This commit is contained in:
Your Name
2025-06-29 19:46:55 +12:00
parent 8e2611e362
commit c9d91ae2ca
2 changed files with 25 additions and 13 deletions

View File

@ -5,6 +5,7 @@
#include <iostream> #include <iostream>
#include <filesystem> #include <filesystem>
#include <sstream> #include <sstream>
#include <set>
#include <algorithm> #include <algorithm>
using json = nlohmann::json; using json = nlohmann::json;
@ -207,7 +208,7 @@ bool GetbinClient::deleteObject(const std::string& hash, const std::string& toke
bool GetbinClient::listPackages(std::vector<std::string>& outPackages) { bool GetbinClient::listPackages(std::vector<std::string>& outPackages) {
try { try {
std::string url = "https://" + SERVER_HOST + "/packages"; std::string url = "https://" + SERVER_HOST + "/dir";
auto response = cpr::Get(cpr::Url{url}, auto response = cpr::Get(cpr::Url{url},
cpr::Header{{"User-Agent", getUserAgent()}}, cpr::Header{{"User-Agent", getUserAgent()}},
@ -217,20 +218,31 @@ bool GetbinClient::listPackages(std::vector<std::string>& outPackages) {
if (response.status_code == 200) { if (response.status_code == 200) {
try { try {
auto resp_json = json::parse(response.text); auto resp_json = json::parse(response.text);
if (resp_json.is_array()) { if (resp_json.contains("entries") && resp_json["entries"].is_array()) {
outPackages.clear(); outPackages.clear();
for (const auto& item : resp_json) { std::set<std::string> uniqueTools;
if (item.is_string()) {
outPackages.push_back(item.get<std::string>()); for (const auto& entry : resp_json["entries"]) {
if (entry.contains("labeltags") && entry["labeltags"].is_array()) {
for (const auto& labeltag : entry["labeltags"]) {
if (labeltag.is_string()) {
std::string tag = labeltag.get<std::string>();
// Extract tool name from "tool:arch" format
size_t colonPos = tag.find(":");
if (colonPos != std::string::npos) {
std::string toolName = tag.substr(0, colonPos);
if (!toolName.empty()) {
uniqueTools.insert(toolName);
}
}
}
}
} }
} }
return true;
} else if (resp_json.contains("packages") && resp_json["packages"].is_array()) { // Convert set to vector
outPackages.clear(); for (const auto& tool : uniqueTools) {
for (const auto& item : resp_json["packages"]) { outPackages.push_back(tool);
if (item.is_string()) {
outPackages.push_back(item.get<std::string>());
}
} }
return true; return true;
} }

View File

@ -824,7 +824,7 @@ int list_packages(int argc, char* argv[]) {
for (const auto& packageName : availablePackages) { for (const auto& packageName : availablePackages) {
std::string status = "Available"; std::string status = "Available";
std::string localVersion = "-"; std::string localVersion = "-";
std::string remoteStatus = ""; std::string remoteStatus = "-";
auto it = installedPackages.find(packageName); auto it = installedPackages.find(packageName);
if (it != installedPackages.end()) { if (it != installedPackages.end()) {