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 <filesystem>
#include <sstream>
#include <set>
#include <algorithm>
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) {
try {
std::string url = "https://" + SERVER_HOST + "/packages";
std::string url = "https://" + SERVER_HOST + "/dir";
auto response = cpr::Get(cpr::Url{url},
cpr::Header{{"User-Agent", getUserAgent()}},
@ -217,20 +218,31 @@ bool GetbinClient::listPackages(std::vector<std::string>& outPackages) {
if (response.status_code == 200) {
try {
auto resp_json = json::parse(response.text);
if (resp_json.is_array()) {
if (resp_json.contains("entries") && resp_json["entries"].is_array()) {
outPackages.clear();
for (const auto& item : resp_json) {
if (item.is_string()) {
outPackages.push_back(item.get<std::string>());
std::set<std::string> uniqueTools;
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()) {
outPackages.clear();
for (const auto& item : resp_json["packages"]) {
if (item.is_string()) {
outPackages.push_back(item.get<std::string>());
}
// Convert set to vector
for (const auto& tool : uniqueTools) {
outPackages.push_back(tool);
}
return true;
}

View File

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