From 9d56a6ff0156fc7d5c7395787a4b060aebb278b8 Mon Sep 17 00:00:00 2001 From: faumaray Date: Tue, 23 Jun 2026 13:49:26 +0300 Subject: [PATCH] Consume Void::Net directly in NetworkClient and callers Delete NetworkClient's to_void_method/to_void_proxy/to_api_response bridge and the Api::RetryConfig member; the client builds Void::Net::Request, sends via Void::Net::HttpClient, returns Void::Net::Response, and retries via an internal Void::Retry policy + retryable-status list. Call sites updated to Void::Net member names: isSuccess()->ok(), statusCode->status, getHeader()->header() (optional), isRedirect()->status range check; proxy isValid()->enabled(), requiresAuth()->has_auth(), isSocks5()->kind == Kind::Socks5. Proxy fields flow through YtDlpManager/AudioDecoder/MusicManager unchanged in spelling. On-disk proxy shape is now Void::Net::ProxyConfig (kind: None/Http/Socks5); config.example.json updated and proxy round-trip verified. Build green. Co-Authored-By: Claude Opus 4.8 --- include/echoion/core/AudioDecoder.hpp | 4 +- include/echoion/core/NetworkClient.hpp | 84 +++++++----- include/echoion/core/YouTubeClient.hpp | 4 +- include/echoion/core/YtDlpManager.hpp | 6 +- src/AudioDecoder.cpp | 10 +- src/Core.cpp | 5 +- src/MusicManager.cpp | 16 +-- src/NetworkClient.cpp | 170 +++++++------------------ src/UrlShortener.cpp | 8 +- src/YouTubeClient.cpp | 42 +++--- src/YtDlpManager.cpp | 30 ++--- src/commands/RpcInfoCommand.cpp | 2 +- 12 files changed, 158 insertions(+), 223 deletions(-) diff --git a/include/echoion/core/AudioDecoder.hpp b/include/echoion/core/AudioDecoder.hpp index e9e739d..3c642e1 100644 --- a/include/echoion/core/AudioDecoder.hpp +++ b/include/echoion/core/AudioDecoder.hpp @@ -60,7 +60,7 @@ namespace Echoion::Core void setOutputFormat(uint32_t sampleRate, uint32_t channels); // Set proxy configuration for network requests - void setProxyConfig(const std::optional& proxy); + void setProxyConfig(const std::optional& proxy); // Hardware acceleration [[nodiscard]] bool isHardwareAccelerated() const @@ -159,7 +159,7 @@ namespace Echoion::Core std::string currentUrl_; std::atomic streamSampleRate_{48000}; - std::optional proxyConfig_; + std::optional proxyConfig_; // Statistics mutable std::mutex statsMutex_; diff --git a/include/echoion/core/NetworkClient.hpp b/include/echoion/core/NetworkClient.hpp index 2d38698..12d7078 100644 --- a/include/echoion/core/NetworkClient.hpp +++ b/include/echoion/core/NetworkClient.hpp @@ -1,11 +1,12 @@ #pragma once #include -#include #include #include #include #include +#include +#include #include #include #include @@ -19,7 +20,8 @@ namespace Echoion::Core // HTTP client implementing Api::INetworkClient. A thin adapter over // Void::Net::HttpClient (HTTP/HTTPS, TLS, SOCKS5 + HTTP-CONNECT proxies); - // retry/backoff is layered here via Void::Retry. + // retry/backoff is layered here via Void::Retry. Speaks Void::Net types + // directly — no echoion-side HTTP mirror. class NetworkClient : public Api::INetworkClient { public: @@ -28,50 +30,54 @@ namespace Echoion::Core ~NetworkClient() override; Api::Result initialize( - const std::optional& proxy = std::nullopt); - void shutdown(); + const std::optional& proxy = + std::nullopt) override; + void shutdown() override; // Synchronous requests - [[nodiscard]] Api::Result + [[nodiscard]] Api::Result get(std::string_view url, - const std::vector& headers = {}); - [[nodiscard]] Api::Result + const std::vector& headers = {}) override; + [[nodiscard]] Api::Result post(std::string_view url, std::string_view body, - const std::vector& headers = {}); - [[nodiscard]] Api::Result - request(const Api::HttpRequest& req); + const std::vector& headers = {}) + override; + [[nodiscard]] Api::Result + request(const Void::Net::Request& req) override; // Asynchronous requests - [[nodiscard]] std::future> + [[nodiscard]] std::future> getAsync(std::string_view url, - const std::vector& headers = {}); - [[nodiscard]] std::future> + const std::vector& headers = {}) + override; + [[nodiscard]] std::future> postAsync(std::string_view url, std::string_view body, - const std::vector& headers = {}); - [[nodiscard]] std::future> - requestAsync(const Api::HttpRequest& req); + const std::vector& headers = {}) + override; + [[nodiscard]] std::future> + requestAsync(const Void::Net::Request& req) override; // Concurrent batch requests - [[nodiscard]] std::vector> - requestBatch(const std::vector& requests); + [[nodiscard]] std::vector> + requestBatch(const std::vector& requests); // JSON helpers using Void::Json reflection template [[nodiscard]] Api::Result getJson(std::string_view url, - const std::vector& headers = {}) + const std::vector& headers = {}) { auto response = get(url, headers); if (!response) { return std::unexpected(response.error()); } - return parseJson(response->bodyAsString()); + return parseJson(response->body); } template [[nodiscard]] Api::Result postJson(std::string_view url, const Body& body, - const std::vector& headers = {}) + const std::vector& headers = {}) { std::string jsonBody = Void::Json::serialize(Void::Json::to_json(body)); @@ -79,17 +85,15 @@ namespace Echoion::Core if (!response) { return std::unexpected(response.error()); } - return parseJson(response->bodyAsString()); + return parseJson(response->body); } // Proxy configuration - void setProxy(const std::optional& proxy); - [[nodiscard]] std::optional getProxy() const; - void clearProxy(); - - // Retry configuration - void setRetryConfig(const Api::RetryConfig& config); - [[nodiscard]] Api::RetryConfig getRetryConfig() const; + void setProxy( + const std::optional& proxy) override; + [[nodiscard]] std::optional + getProxy() const override; + void clearProxy() override; private: @@ -117,16 +121,26 @@ namespace Echoion::Core // Execute with retry/backoff (Void::Retry); single attempt via // Void::Net::HttpClient. - [[nodiscard]] Api::Result - executeWithRetry(const Api::HttpRequest& req); - [[nodiscard]] Api::Result - executeRequest(const Api::HttpRequest& req); + [[nodiscard]] Api::Result + executeWithRetry(const Void::Net::Request& req); + [[nodiscard]] Api::Result + executeRequest(const Void::Net::Request& req); - std::optional proxy_; - Api::RetryConfig retryConfig_; + std::optional proxy_; mutable std::mutex mutex_; std::atomic initialized_{false}; + // Retry policy + the HTTP statuses worth retrying. Internal + // defaults — retry tuning is not part of the public client API. + Void::Retry::Policy retryPolicy_{ + .max_attempts = 4, + .backoff = Void::Retry::ExponentialBackoff{ + .base = std::chrono::milliseconds(1000), + .max = std::chrono::milliseconds(30000), + .multiplier = 2.0}}; + std::vector retryableStatusCodes_{408, 429, 500, + 502, 503, 504}; + // Worker pool backing the *Async / requestBatch fan-outs, replacing // a per-call std::async OS-thread spawn with bounded thread reuse. Void::Concurrency::ThreadPool pool_; diff --git a/include/echoion/core/YouTubeClient.hpp b/include/echoion/core/YouTubeClient.hpp index a4ca74a..64afbd4 100644 --- a/include/echoion/core/YouTubeClient.hpp +++ b/include/echoion/core/YouTubeClient.hpp @@ -106,8 +106,8 @@ namespace Echoion::Core void setCookiesFromBrowser(const std::string& browser); // Configure proxy for yt-dlp - void setProxyConfig(const std::optional& proxy); - [[nodiscard]] std::optional + void setProxyConfig(const std::optional& proxy); + [[nodiscard]] std::optional getProxyConfig() const; // Set YouTube API key for enhanced playlist resolution (optional) diff --git a/include/echoion/core/YtDlpManager.hpp b/include/echoion/core/YtDlpManager.hpp index 2d37309..6048458 100644 --- a/include/echoion/core/YtDlpManager.hpp +++ b/include/echoion/core/YtDlpManager.hpp @@ -67,8 +67,8 @@ namespace Echoion::Core [[nodiscard]] std::vector getCookieArgs() const; // Set proxy configuration for yt-dlp - void setProxyConfig(const std::optional& proxy); - [[nodiscard]] std::optional + void setProxyConfig(const std::optional& proxy); + [[nodiscard]] std::optional getProxyConfig() const; // Configure thread pool size for async operations (default: 4) @@ -116,7 +116,7 @@ namespace Echoion::Core std::optional cookiesFromBrowser_; // Proxy configuration - std::optional proxyConfig_; + std::optional proxyConfig_; mutable std::mutex proxyMutex_; // Thread pool for async operations (Void worker pool; recreated diff --git a/src/AudioDecoder.cpp b/src/AudioDecoder.cpp index 291418f..20166d6 100644 --- a/src/AudioDecoder.cpp +++ b/src/AudioDecoder.cpp @@ -152,13 +152,13 @@ namespace Echoion::Core av_dict_set(&options, "analyzeduration", "20000000", 0); av_dict_set(&options, "probesize", "10240000", 0); - if (proxyConfig_.has_value() && proxyConfig_->isValid()) { + if (proxyConfig_.has_value() && proxyConfig_->enabled()) { std::string proxyUrl; - if (proxyConfig_->isSocks5()) { + if ((proxyConfig_->kind == Void::Net::ProxyConfig::Kind::Socks5)) { // Use standard socks5:// scheme. FFmpeg http protocol handles // this correctly. socks5h:// is often rejected by the http // protocol handler, causing proxy bypass. - if (proxyConfig_->requiresAuth()) { + if (proxyConfig_->has_auth()) { proxyUrl = std::format( "socks5://{}:{}@{}:{}", *proxyConfig_->username, *proxyConfig_->password, proxyConfig_->host, @@ -168,7 +168,7 @@ namespace Echoion::Core proxyConfig_->port); } } else { - if (proxyConfig_->requiresAuth()) { + if (proxyConfig_->has_auth()) { proxyUrl = std::format( "http://{}:{}@{}:{}", *proxyConfig_->username, *proxyConfig_->password, proxyConfig_->host, @@ -491,7 +491,7 @@ namespace Echoion::Core } void AudioDecoder::setProxyConfig( - const std::optional& proxy) + const std::optional& proxy) { proxyConfig_ = proxy; } diff --git a/src/Core.cpp b/src/Core.cpp index 3597e79..1376890 100644 --- a/src/Core.cpp +++ b/src/Core.cpp @@ -827,9 +827,8 @@ namespace Echoion::Core commandManager_->setServerConfig(config); } - // Update network proxy if changed - if (networkClient_ && - config.network.proxy != networkClient_->getProxy()) { + // Re-apply the network proxy from config (idempotent store). + if (networkClient_) { networkClient_->setProxy(config.network.proxy); } diff --git a/src/MusicManager.cpp b/src/MusicManager.cpp index ef2cc05..0633343 100644 --- a/src/MusicManager.cpp +++ b/src/MusicManager.cpp @@ -32,11 +32,11 @@ namespace Echoion::Core // NetworkClient is already initialized by Core, just update proxy if // needed - if (networkConfig.proxy.has_value() && networkConfig.proxy->isValid()) { + if (networkConfig.proxy.has_value() && networkConfig.proxy->enabled()) { networkClient_->setProxy(networkConfig.proxy); ECHOION_LOG_INFO(std::format( "NetworkClient using {} proxy: {}:{}", - networkConfig.proxy->isSocks5() ? "SOCKS5" : "HTTP", + (networkConfig.proxy->kind == Void::Net::ProxyConfig::Kind::Socks5) ? "SOCKS5" : "HTTP", networkConfig.proxy->host, networkConfig.proxy->port)); } @@ -56,7 +56,7 @@ namespace Echoion::Core } // Configure proxy for YouTube client - if (networkConfig.proxy.has_value() && networkConfig.proxy->isValid()) { + if (networkConfig.proxy.has_value() && networkConfig.proxy->enabled()) { youTubeClient_->setProxyConfig(networkConfig.proxy); } @@ -93,11 +93,11 @@ namespace Echoion::Core TEAMSPEAK_CHANNELS); // Set proxy config from NetworkConfig if enabled - if (networkConfig.proxy.has_value() && networkConfig.proxy->isValid()) { + if (networkConfig.proxy.has_value() && networkConfig.proxy->enabled()) { audioDecoder_->setProxyConfig(networkConfig.proxy); ECHOION_LOG_INFO( std::format("AudioDecoder using {} proxy: {}:{}", - networkConfig.proxy->isSocks5() ? "SOCKS5" : "HTTP", + (networkConfig.proxy->kind == Void::Net::ProxyConfig::Kind::Socks5) ? "SOCKS5" : "HTTP", networkConfig.proxy->host, networkConfig.proxy->port)); } @@ -231,7 +231,7 @@ namespace Echoion::Core // proxy const auto& networkConfig = ECHOION_NETWORK; if (!openResult && networkConfig.proxy.has_value() && - networkConfig.proxy->isValid()) { + networkConfig.proxy->enabled()) { ECHOION_LOG_INFO( "Direct open failed, trying download through proxy..."); auto downloadedPath = downloadAudioForPlayback(*streamUrl); @@ -2263,10 +2263,10 @@ Subscriptions are persistent across server reconnects.)"; response.error().message)); } - if (response->statusCode != 200) { + if (response->status != 200) { return Api::fail( Api::ErrorCode::NetworkError, - std::format("HTTP error {}: {}", response->statusCode, + std::format("HTTP error {}: {}", response->status, response->body.substr(0, 100))); } diff --git a/src/NetworkClient.cpp b/src/NetworkClient.cpp index 128cf9d..689931a 100644 --- a/src/NetworkClient.cpp +++ b/src/NetworkClient.cpp @@ -7,56 +7,11 @@ namespace Echoion::Core { - namespace - { - [[nodiscard]] Void::Net::Method to_void_method(Api::HttpMethod m) - { - switch (m) { - case Api::HttpMethod::GET: return Void::Net::Method::Get; - case Api::HttpMethod::POST: return Void::Net::Method::Post; - case Api::HttpMethod::PUT: return Void::Net::Method::Put; - case Api::HttpMethod::DELETE: return Void::Net::Method::Delete; - case Api::HttpMethod::PATCH: return Void::Net::Method::Patch; - case Api::HttpMethod::HEAD: return Void::Net::Method::Head; - case Api::HttpMethod::OPTIONS: return Void::Net::Method::Options; - } - return Void::Net::Method::Get; - } - - [[nodiscard]] Void::Net::ProxyConfig - to_void_proxy(const Api::ProxyConfig& p) - { - Void::Net::ProxyConfig out; - out.kind = p.isSocks5() ? Void::Net::ProxyConfig::Kind::Socks5 - : Void::Net::ProxyConfig::Kind::Http; - out.host = p.host; - out.port = p.port; - out.username = p.username; - out.password = p.password; - return out; - } - - [[nodiscard]] Api::HttpResponse - to_api_response(Void::Net::Response&& r) - { - Api::HttpResponse out; - out.statusCode = static_cast(r.status); - out.responseTime = r.elapsed; - out.body = std::move(r.body); - out.headers.reserve(r.headers.size()); - for (auto& h : r.headers) { - out.headers.emplace_back(std::move(h.name), - std::move(h.value)); - } - return out; - } - } // namespace - NetworkClient::NetworkClient() = default; NetworkClient::~NetworkClient() { shutdown(); } - Api::Result - NetworkClient::initialize(const std::optional& proxy) + Api::Result NetworkClient::initialize( + const std::optional& proxy) { proxy_ = proxy; initialized_ = true; @@ -67,131 +22,109 @@ namespace Echoion::Core void NetworkClient::shutdown() { initialized_ = false; } - Api::Result NetworkClient::executeRequest( - const Api::HttpRequest& req) + Api::Result + NetworkClient::executeRequest(const Void::Net::Request& req) { Void::Net::HttpClient client; - const auto active = req.proxy.has_value() ? req.proxy : proxy_; - if (active && active->isValid()) { - client.set_proxy(to_void_proxy(*active)); + const auto active = proxy_; + if (active && active->enabled()) { + client.set_proxy(*active); } - Void::Net::Request vreq; - vreq.method = to_void_method(req.method); - vreq.url = req.url; - vreq.timeout = - std::chrono::duration_cast(req.timeout); - for (const auto& h : req.headers) { - vreq.headers.push_back({h.name, h.value}); - } - if (req.body) { - vreq.body = std::string(req.body->begin(), req.body->end()); - } - - auto result = client.send(vreq); + auto result = client.send(req); if (!result) { return Api::fail(Api::ErrorCode::NetworkError, - result.error().message()); + result.error().message()); } - return to_api_response(std::move(*result)); + return std::move(*result); } - Api::Result NetworkClient::executeWithRetry( - const Api::HttpRequest& req) + Api::Result + NetworkClient::executeWithRetry(const Void::Net::Request& req) { - const Void::Retry::Policy policy{ - .max_attempts = - static_cast(retryConfig_.maxRetries) + 1, - .backoff = Void::Retry::ExponentialBackoff{ - .base = retryConfig_.initialDelay, - .max = retryConfig_.maxDelay, - .multiplier = - static_cast(retryConfig_.backoffMultiplier)}}; - return Void::Retry::retry_while( - policy, [&] { return executeRequest(req); }, - [this](const Api::Result& result) { + retryPolicy_, [&] { return executeRequest(req); }, + [this](const Api::Result& result) { if (!result) { ECHOION_LOG_WARNING(std::format( "Request error: {}, retrying", result.error().message)); return true; } - if (result->isError()) { - const auto& codes = retryConfig_.retryableStatusCodes; - if (std::find(codes.begin(), codes.end(), - result->statusCode) != codes.end()) { - ECHOION_LOG_WARNING(std::format( - "Request failed with status {}, retrying", - result->statusCode)); - return true; - } + // Retry only on the configured retryable HTTP statuses. + const auto& codes = retryableStatusCodes_; + if (std::find(codes.begin(), codes.end(), result->status) != + codes.end()) { + ECHOION_LOG_WARNING( + std::format("Request failed with status {}, retrying", + result->status)); + return true; } return false; }); } - Api::Result - NetworkClient::request(const Api::HttpRequest& req) + Api::Result + NetworkClient::request(const Void::Net::Request& req) { return executeWithRetry(req); } - Api::Result + Api::Result NetworkClient::get(std::string_view url, - const std::vector& headers) + const std::vector& headers) { - Api::HttpRequest req; + Void::Net::Request req; req.url = std::string(url); - req.method = Api::HttpMethod::GET; + req.method = Void::Net::Method::Get; req.headers = headers; return request(req); } - Api::Result + Api::Result NetworkClient::post(std::string_view url, std::string_view body, - const std::vector& headers) + const std::vector& headers) { - Api::HttpRequest req; + Void::Net::Request req; req.url = std::string(url); - req.method = Api::HttpMethod::POST; + req.method = Void::Net::Method::Post; req.headers = headers; - req.body = std::vector(body.begin(), body.end()); + req.body = std::string(body); return request(req); } - std::future> + std::future> NetworkClient::getAsync(std::string_view url, - const std::vector& headers) + const std::vector& headers) { return pool_.submit([this, u = std::string(url), headers] { return get(u, headers); }); } - std::future> + std::future> NetworkClient::postAsync(std::string_view url, std::string_view body, - const std::vector& headers) + const std::vector& headers) { return pool_.submit([this, u = std::string(url), b = std::string(body), headers] { return post(u, b, headers); }); } - std::future> - NetworkClient::requestAsync(const Api::HttpRequest& req) + std::future> + NetworkClient::requestAsync(const Void::Net::Request& req) { return pool_.submit([this, req] { return request(req); }); } - std::vector> + std::vector> NetworkClient::requestBatch( - const std::vector& requests) + const std::vector& requests) { - std::vector>> futures; + std::vector>> futures; futures.reserve(requests.size()); for (const auto& req : requests) { futures.push_back(requestAsync(req)); } - std::vector> results; + std::vector> results; results.reserve(requests.size()); for (auto& f : futures) { results.push_back(f.get()); @@ -199,13 +132,14 @@ namespace Echoion::Core return results; } - void NetworkClient::setProxy(const std::optional& proxy) + void NetworkClient::setProxy( + const std::optional& proxy) { std::lock_guard lock(mutex_); proxy_ = proxy; } - std::optional NetworkClient::getProxy() const + std::optional NetworkClient::getProxy() const { std::lock_guard lock(mutex_); return proxy_; @@ -217,16 +151,4 @@ namespace Echoion::Core proxy_ = std::nullopt; } - void NetworkClient::setRetryConfig(const Api::RetryConfig& config) - { - std::lock_guard lock(mutex_); - retryConfig_ = config; - } - - Api::RetryConfig NetworkClient::getRetryConfig() const - { - std::lock_guard lock(mutex_); - return retryConfig_; - } - } // namespace Echoion::Core diff --git a/src/UrlShortener.cpp b/src/UrlShortener.cpp index 0b5e155..3337bd2 100644 --- a/src/UrlShortener.cpp +++ b/src/UrlShortener.cpp @@ -55,7 +55,7 @@ namespace Echoion::Core std::string jsonBody = std::format(R"({{"longUrl":"{}"}})", originalUrl); - std::vector headers = { + std::vector headers = { {"Content-Type", "application/json"}, {"User-Agent", "EchoionBot/1.0"}}; @@ -71,12 +71,12 @@ namespace Echoion::Core "Failed to shorten URL"); } - if (!response->isSuccess()) { + if (!response->ok()) { ECHOION_LOG_WARNING(std::format("URL shortening returned HTTP {}", - response->statusCode)); + response->status)); return Api::fail(Api::ErrorCode::NetworkError, std::format("Shortening service returned HTTP {}", - response->statusCode)); + response->status)); } try { diff --git a/src/YouTubeClient.cpp b/src/YouTubeClient.cpp index f4d5338..c1ea55d 100644 --- a/src/YouTubeClient.cpp +++ b/src/YouTubeClient.cpp @@ -72,21 +72,21 @@ namespace Echoion::Core } void YouTubeClient::setProxyConfig( - const std::optional& proxy) + const std::optional& proxy) { if (ytDlpManager_) { ytDlpManager_->setProxyConfig(proxy); } std::lock_guard lock(configMutex_); - if (proxy.has_value() && proxy->isValid()) { + if (proxy.has_value() && proxy->enabled()) { ECHOION_LOG_INFO( std::format("YouTubeClient proxy configured: {}:{}", proxy->host, proxy->port)); } } - std::optional YouTubeClient::getProxyConfig() const + std::optional YouTubeClient::getProxyConfig() const { if (ytDlpManager_) { return ytDlpManager_->getProxyConfig(); @@ -413,8 +413,8 @@ namespace Echoion::Core // Use shared promise so detached thread can safely complete auto responsePromise = - std::make_shared>>(); - std::future> responseFuture = + std::make_shared>>(); + std::future> responseFuture = responsePromise->get_future(); std::thread apiThread( @@ -444,7 +444,7 @@ namespace Echoion::Core ECHOION_LOG_DEBUG("API request thread joined"); // Get the response - Api::Result response; + Api::Result response; try { response = responseFuture.get(); } catch (const std::exception& e) { @@ -457,17 +457,17 @@ namespace Echoion::Core // Log response status if (response) { ECHOION_LOG_DEBUG( - std::format("API response status: {}", response->statusCode)); + std::format("API response status: {}", response->status)); } else { ECHOION_LOG_WARNING(std::format("API request failed: {}", response.error().message)); } - if (!response || !response->isSuccess()) { + if (!response || !response->ok()) { return Api::fail( Api::ErrorCode::NetworkError, std::format("YouTube API search failed: {}", - response ? std::to_string(response->statusCode) + response ? std::to_string(response->status) : "no response")); } @@ -600,8 +600,8 @@ namespace Echoion::Core // Execute with timeout (5 seconds) to avoid blocking // Use shared promise so detached thread can safely complete auto responsePromise = - std::make_shared>>(); - std::future> responseFuture = + std::make_shared>>(); + std::future> responseFuture = responsePromise->get_future(); std::thread durationThread( @@ -624,7 +624,7 @@ namespace Echoion::Core durationThread.join(); - Api::Result response; + Api::Result response; try { response = responseFuture.get(); } catch (const std::exception& e) { @@ -633,7 +633,7 @@ namespace Echoion::Core return; } - if (!response || !response->isSuccess()) { + if (!response || !response->ok()) { ECHOION_LOG_WARNING( "Failed to fetch video durations from YouTube API"); return; @@ -986,7 +986,7 @@ namespace Echoion::Core std::string apiUrl = buildPlaylistApiUrl(playlistId, pageToken); auto response = networkClient_->get(apiUrl); - if (!response || !response->isSuccess()) { + if (!response || !response->ok()) { ECHOION_LOG_WARNING( "YouTube API request failed, falling back to yt-dlp"); break; // Fall back to yt-dlp @@ -1235,7 +1235,7 @@ namespace Echoion::Core ECHOION_LOG_DEBUG( std::format("Following redirect for: {}", url_str)); - std::vector headers = { + std::vector headers = { {"User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " "AppleWebKit/537.36"}}; @@ -1245,22 +1245,22 @@ namespace Echoion::Core if (response) { // Check if we got a redirect - if (response->isRedirect()) { - auto location = response->getHeader("location"); + if (response->status >= 300 && response->status < 400) { + auto location = response->header("location"); if (location.has_value()) { ECHOION_LOG_DEBUG( std::format("Redirected to: {}", *location)); - url_str = *location; + url_str = std::string(*location); } - } else if (response->isSuccess()) { + } else if (response->ok()) { // Some shorteners might return the target in the body or we // might need to look at the URL after any automatic // redirect following Try to extract from current URL or // response - auto finalUrl = response->getHeader( + auto finalUrl = response->header( "x-final-url"); // Some clients add this if (finalUrl.has_value()) { - url_str = *finalUrl; + url_str = std::string(*finalUrl); } } } diff --git a/src/YtDlpManager.cpp b/src/YtDlpManager.cpp index 208d118..8bab306 100644 --- a/src/YtDlpManager.cpp +++ b/src/YtDlpManager.cpp @@ -221,11 +221,11 @@ namespace Echoion::Core } void YtDlpManager::setProxyConfig( - const std::optional& proxy) + const std::optional& proxy) { std::lock_guard lock(proxyMutex_); proxyConfig_ = proxy; - if (proxy.has_value() && proxy->isValid()) { + if (proxy.has_value() && proxy->enabled()) { ECHOION_LOG_INFO(std::format("yt-dlp proxy configured: {}:{}", proxy->host, proxy->port)); } else { @@ -233,7 +233,7 @@ namespace Echoion::Core } } - std::optional YtDlpManager::getProxyConfig() const + std::optional YtDlpManager::getProxyConfig() const { std::lock_guard lock(proxyMutex_); return proxyConfig_; @@ -244,15 +244,15 @@ namespace Echoion::Core std::lock_guard lock(proxyMutex_); std::vector proxyArgs; - if (!proxyConfig_.has_value() || !proxyConfig_->isValid()) { + if (!proxyConfig_.has_value() || !proxyConfig_->enabled()) { return proxyArgs; } const auto& proxy = *proxyConfig_; std::string proxyUrl; - if (proxy.isSocks5()) { - if (proxy.requiresAuth()) { + if (proxy.kind == Void::Net::ProxyConfig::Kind::Socks5) { + if (proxy.has_auth()) { proxyUrl = std::format("socks5://{}:{}@{}:{}", *proxy.username, *proxy.password, proxy.host, proxy.port); } else { @@ -260,7 +260,7 @@ namespace Echoion::Core std::format("socks5://{}:{}", proxy.host, proxy.port); } } else { - if (proxy.requiresAuth()) { + if (proxy.has_auth()) { proxyUrl = std::format("http://{}:{}@{}:{}", *proxy.username, *proxy.password, proxy.host, proxy.port); } else { @@ -285,12 +285,12 @@ namespace Echoion::Core ECHOION_LOG_INFO( std::format("Downloading yt-dlp from: {}", downloadUrl)); - std::vector headers = { + std::vector headers = { {"User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36"}}; // Follow redirects manually (GitHub releases use 302 redirects) - Api::HttpResponse response; + Void::Net::Response response; int redirectCount = 0; constexpr int maxRedirects = 5; @@ -305,8 +305,8 @@ namespace Echoion::Core response = std::move(*result); // Check for redirect (3xx status codes) - if (response.statusCode >= 300 && response.statusCode < 400) { - auto location = response.getHeader("location"); + if (response.status >= 300 && response.status < 400) { + auto location = response.header("location"); if (!location.has_value()) { return Api::fail( Api::ErrorCode::NetworkError, @@ -314,7 +314,7 @@ namespace Echoion::Core } // Handle relative URLs - std::string newUrl = *location; + std::string newUrl(*location); if (newUrl.starts_with("/")) { // Relative to host - extract host from current URL auto pos = downloadUrl.find("://"); @@ -329,7 +329,7 @@ namespace Echoion::Core } ECHOION_LOG_INFO(std::format("Following redirect (HTTP {}): {}", - response.statusCode, newUrl)); + response.status, newUrl)); downloadUrl = newUrl; redirectCount++; continue; @@ -338,10 +338,10 @@ namespace Echoion::Core break; } - if (!response.isSuccess()) { + if (!response.ok()) { return Api::fail(Api::ErrorCode::NetworkError, std::format("Failed to download yt-dlp: HTTP {}", - response.statusCode)); + response.status)); } ECHOION_LOG_INFO( diff --git a/src/commands/RpcInfoCommand.cpp b/src/commands/RpcInfoCommand.cpp index 2c1bb7f..cb0de6c 100644 --- a/src/commands/RpcInfoCommand.cpp +++ b/src/commands/RpcInfoCommand.cpp @@ -43,7 +43,7 @@ namespace Echoion::Core for (const auto& service : ipServices) { try { auto result = networkClient->get(service); - if (result && result->isSuccess()) { + if (result && result->ok()) { // Extract IP from response body (trim whitespace) std::string ip = result->body; // Remove whitespace and newlines