|
|
|
@ -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<u8> default_logo_small; |
|
|
|
@ -227,22 +228,58 @@ void WriteCachedJson(std::string_view json) { |
|
|
|
|
|
|
|
std::optional<std::string> DownloadReleasesJson() { |
|
|
|
try { |
|
|
|
httplib::SSLClient cli{"api.github.com", 443}; |
|
|
|
cli.set_connection_timeout(10); |
|
|
|
cli.set_read_timeout(10); |
|
|
|
#ifdef YUZU_BUNDLED_OPENSSL
|
|
|
|
const auto url = "https://git.eden-emu.dev"; |
|
|
|
#else
|
|
|
|
const auto url = "git.eden-emu.dev"; |
|
|
|
#endif
|
|
|
|
|
|
|
|
httplib::Headers headers{ |
|
|
|
{"User-Agent", "Eden"}, |
|
|
|
{"Accept", "application/vnd.github+json"}, |
|
|
|
}; |
|
|
|
// TODO(crueter): This is duplicated between frontend and here.
|
|
|
|
constexpr auto path = GitHubAPI_EdenReleases; |
|
|
|
|
|
|
|
constexpr std::size_t timeout_seconds = 15; |
|
|
|
|
|
|
|
std::unique_ptr<httplib::Client> client = std::make_unique<httplib::Client>(url); |
|
|
|
client->set_connection_timeout(timeout_seconds); |
|
|
|
client->set_read_timeout(timeout_seconds); |
|
|
|
client->set_write_timeout(timeout_seconds); |
|
|
|
|
|
|
|
// TODO(crueter): automate this in some way...
|
|
|
|
#ifdef YUZU_BUNDLED_OPENSSL
|
|
|
|
cli.load_ca_cert_store(kCert, sizeof(kCert)); |
|
|
|
client->load_ca_cert_store(kCert, sizeof(kCert)); |
|
|
|
#endif
|
|
|
|
|
|
|
|
if (auto res = cli.Get(GitHubAPI_EdenReleases, headers); res && res->status < 400) { |
|
|
|
return res->body; |
|
|
|
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<u8> 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<u8> 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(); |
|
|
|
}); |
|
|
|
|