From c05d99922599bef03a64eb61646e6fe6fdd5f7e6 Mon Sep 17 00:00:00 2001 From: crueter Date: Wed, 8 Apr 2026 22:09:55 +0200 Subject: [PATCH] [bcat] Fix news to use Forgejo releases instead (#3841) Signed-off-by: crueter Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3841 --- .../hle/service/bcat/news/builtin_news.cpp | 73 ++++++++++++++----- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/src/core/hle/service/bcat/news/builtin_news.cpp b/src/core/hle/service/bcat/news/builtin_news.cpp index d24431cdbc..66cf5bb697 100644 --- a/src/core/hle/service/bcat/news/builtin_news.cpp +++ b/src/core/hle/service/bcat/news/builtin_news.cpp @@ -35,7 +35,8 @@ namespace Service::News { namespace { -constexpr const char* GitHubAPI_EdenReleases = "/repos/eden-emulator/Releases/releases"; +// TODO(crueter): COMPILE DEFINITION +constexpr const char* GitHubAPI_EdenReleases = "/api/v1/repos/eden-emu/eden/releases"; // Cached logo data std::vector default_logo_small; @@ -227,22 +228,58 @@ void WriteCachedJson(std::string_view json) { std::optional DownloadReleasesJson() { try { - httplib::SSLClient cli{"api.github.com", 443}; - cli.set_connection_timeout(10); - cli.set_read_timeout(10); - - httplib::Headers headers{ - {"User-Agent", "Eden"}, - {"Accept", "application/vnd.github+json"}, - }; - - // TODO(crueter): automate this in some way... #ifdef YUZU_BUNDLED_OPENSSL - cli.load_ca_cert_store(kCert, sizeof(kCert)); + const auto url = "https://git.eden-emu.dev"; +#else + const auto url = "git.eden-emu.dev"; #endif - if (auto res = cli.Get(GitHubAPI_EdenReleases, headers); res && res->status < 400) { - return res->body; + // TODO(crueter): This is duplicated between frontend and here. + constexpr auto path = GitHubAPI_EdenReleases; + + constexpr std::size_t timeout_seconds = 15; + + std::unique_ptr client = std::make_unique(url); + client->set_connection_timeout(timeout_seconds); + client->set_read_timeout(timeout_seconds); + client->set_write_timeout(timeout_seconds); + +#ifdef YUZU_BUNDLED_OPENSSL + client->load_ca_cert_store(kCert, sizeof(kCert)); +#endif + + if (client == nullptr) { + LOG_ERROR(Service_BCAT, "Invalid URL {}{}", url, path); + return {}; + } + + httplib::Request request{ + .method = "GET", + .path = path, + }; + + client->set_follow_location(true); + httplib::Result result = client->send(request); + + if (!result) { + LOG_ERROR(Service_BCAT, "GET to {}{} returned null", url, path); + return {}; + } else if (result->status < 400) { + return result->body; + } + + if (result->status >= 400) { + LOG_ERROR(Service_BCAT, + "GET to {}{} returned error status code: {}", + url, + path, + result->status); + return {}; + } + + if (!result->headers.contains("content-type")) { + LOG_ERROR(Service_BCAT, "GET to {}{} returned no content", url, path); + return {}; } } catch (...) { LOG_WARNING(Service_BCAT, " failed to download releases"); @@ -332,7 +369,7 @@ std::string FormatBody(const nlohmann::json& release, std::string_view title) { body.pop_back(); } - body += "\n\n... View more on GitHub"; + body += "\n\n... View more on Forgejo"; } return body; @@ -489,7 +526,7 @@ std::vector BuildMsgpack(std::string_view title, std::string_view body, w.WriteString(""); w.WriteKey("allow_domains"); - w.WriteString("^https?://github.com(/|$)"); + w.WriteString("^https?://git.eden-emu.dev(/|$)"); // More link w.WriteKey("more"); @@ -499,7 +536,7 @@ std::vector BuildMsgpack(std::string_view title, std::string_view body, w.WriteKey("url"); w.WriteString(html_url); w.WriteKey("text"); - w.WriteString("Open GitHub"); + w.WriteString("Open Forgejo"); // Body w.WriteKey("body"); @@ -536,7 +573,7 @@ void EnsureBuiltinNewsLoaded() { if (const auto fresh = DownloadReleasesJson()) { WriteCachedJson(*fresh); ImportReleases(*fresh); - LOG_DEBUG(Service_BCAT, "news: {} entries updated from GitHub", NewsStorage::Instance().ListAll().size()); + LOG_DEBUG(Service_BCAT, "news: {} entries updated from Forgejo", NewsStorage::Instance().ListAll().size()); } }).detach(); });