mirror of https://github.com/acidicoala/SmokeAPI
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
C++
47 lines
1.6 KiB
C++
#include <core/api.hpp>
|
|
#include <koalabox/logger.hpp>
|
|
#include <koalabox/http_client.hpp>
|
|
|
|
namespace api {
|
|
|
|
struct SteamResponse {
|
|
uint32_t success = 0;
|
|
Vector<DLC> dlcs;
|
|
|
|
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(SteamResponse, success, dlcs) // NOLINT(misc-const-correctness)
|
|
};
|
|
|
|
std::optional<Vector<DLC>> fetch_dlcs_from_github(AppId_t app_id) noexcept {
|
|
try {
|
|
const auto* url =
|
|
"https://raw.githubusercontent.com/acidicoala/public-entitlements/main/steam/v2/dlc.json";
|
|
const auto json = koalabox::http_client::fetch_json(url);
|
|
const auto response = json.get<AppDlcNameMap>();
|
|
|
|
return DLC::get_dlcs_from_apps(response, app_id);
|
|
} catch (const Json::exception& e) {
|
|
LOG_ERROR("Failed to fetch dlc list from GitHub: {}", e.what())
|
|
return std::nullopt;
|
|
}
|
|
}
|
|
|
|
std::optional<Vector<DLC>> fetch_dlcs_from_steam(AppId_t app_id) noexcept {
|
|
try {
|
|
const auto url = fmt::format("https://store_mode.steampowered.com/dlc/{}/ajaxgetdlclist", app_id);
|
|
const auto json = koalabox::http_client::fetch_json(url);
|
|
|
|
const auto response = json.get<SteamResponse>();
|
|
|
|
if (response.success != 1) {
|
|
throw std::runtime_error("Web API responded with 'success' != 1");
|
|
}
|
|
|
|
return response.dlcs;
|
|
} catch (const Exception& e) {
|
|
LOG_ERROR("Failed to fetch dlc list from Steam: {}", e.what())
|
|
return std::nullopt;
|
|
}
|
|
}
|
|
|
|
}
|