From 9f06af6c8043bf27b506cdd141b9d8260c42691e Mon Sep 17 00:00:00 2001 From: faumaray Date: Thu, 16 Jul 2026 19:59:45 +0300 Subject: [PATCH] Update Signed-off-by: faumaray --- CMakeLists.txt | 8 ++--- include/echoion/core/Core.hpp | 2 +- src/Core.cpp | 45 ++++++++++++++++++------ src/SignatureCipher.cpp | 64 +++++++++++++++++------------------ src/YtDlpManager.cpp | 4 +++ 5 files changed, 76 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 531fdef..a0a2778 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,10 +41,10 @@ target_link_libraries(EchoionCore PUBLIC find_package(PkgConfig REQUIRED) pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET - libavformat - libavcodec - libswresample - libavutil + libavformat>=59 + libavcodec>=59 + libswresample>=4 + libavutil>=57 ) CPMAddPackage( diff --git a/include/echoion/core/Core.hpp b/include/echoion/core/Core.hpp index 8ac2b39..13394b7 100644 --- a/include/echoion/core/Core.hpp +++ b/include/echoion/core/Core.hpp @@ -184,7 +184,7 @@ namespace Echoion::Core // Build the console + split-file logging stack and install it as // the global Void::Log sink (logSink_ must outlive logging). - void installLogging(); + void installLogging(const std::filesystem::path& logDirectory); // Guard helper: ok if initialized, else a ServiceUnavailable error. [[nodiscard]] Api::Result requireInitialized() const noexcept; diff --git a/src/Core.cpp b/src/Core.cpp index 58485d7..de81e65 100644 --- a/src/Core.cpp +++ b/src/Core.cpp @@ -19,7 +19,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -31,6 +33,16 @@ namespace Echoion::Core { namespace { + std::filesystem::path + stateDirectory(const std::filesystem::path& configPath) + { + if (const char* configured = std::getenv("ECHOION_STATE_DIR"); + configured && *configured != '\0') { + return std::filesystem::path{configured}; + } + return configPath.parent_path(); + } + // Decode cached avatar bytes before serving them over HTTP. Returns // empty on malformed input. #ifdef ECHOION_WITH_WEB @@ -140,7 +152,8 @@ namespace Echoion::Core // Build the console + split-file logging stack and install it as the // process-wide Void::Log sink. Replaces the old ILogger/LoggerRegistry // indirection; every ECHOION_LOG_* macro is now a Void::Log:: call. - [[nodiscard]] std::shared_ptr buildLogSink() + [[nodiscard]] std::shared_ptr + buildLogSink(const std::filesystem::path& logDirectory) { namespace VL = Void::Logging; auto multi = std::make_shared(); @@ -155,7 +168,7 @@ namespace Echoion::Core opts.combined = true; opts.max_bytes = 10 * 1024 * 1024; opts.max_files = 5; - if (auto fileSink = VL::SplitFileLogger::open("logs", opts)) { + if (auto fileSink = VL::SplitFileLogger::open(logDirectory, opts)) { (*fileSink)->set_formatter(formatter); multi->add(std::shared_ptr(std::move(*fileSink))); } @@ -179,9 +192,9 @@ namespace Echoion::Core Core::Core() = default; - void Core::installLogging() + void Core::installLogging(const std::filesystem::path& logDirectory) { - logSink_ = buildLogSink(); + logSink_ = buildLogSink(logDirectory); Void::Log::set_sink(Void::Log::make_sink(logSink_)); Void::Log::set_min_level(Void::Log::Level::Debug); } @@ -213,9 +226,18 @@ namespace Echoion::Core return Api::fail(Api::ErrorCode::AlreadyExists, "Core already initialized"); } - installLogging(); // Store config path for later reload configPath_ = configPath; + const auto stateDir = stateDirectory(configPath); + std::error_code stateDirectoryError; + std::filesystem::create_directories(stateDir, stateDirectoryError); + installLogging(stateDir / "logs"); + if (stateDirectoryError) { + Void::Log::warn( + "Core", "{}", + std::format("Failed to create state directory '{}': {}", + stateDir.string(), stateDirectoryError.message())); + } // Load config from file (Core-internal, Plugin doesn't need to know // about AppConfig structure) @@ -265,10 +287,14 @@ namespace Echoion::Core // Lyrics provider (lrclib) — shares the proxy-aware network client. lyricsService_ = std::make_shared(networkClient_); - // Initialize database alongside config file + // Mutable runtime data belongs in the selected state directory. Keeping + // it beside the read-mostly configuration makes system installs attempt + // to write under /etc and prevents portable self-contained layouts from + // moving state as a unit. + // Initialize database in the writable state directory. database_ = std::make_shared(); Api::DatabaseConfig dbConfig; - dbConfig.path = configPath.parent_path() / "echoion.db"; + dbConfig.path = stateDir / "echoion.db"; auto dbResult = database_->initialize(dbConfig); if (!dbResult) { Void::Log::warn("Core", "{}", @@ -496,7 +522,7 @@ namespace Echoion::Core server->broadcastEvent("plugins.updated", "{}"); }); } - extensionPlugins_->loadDirectory(configPath.parent_path() / "plugins"); + extensionPlugins_->loadDirectory(stateDir / "plugins"); #ifdef ECHOION_WITH_WEB // Browser web interface (independent of the RPC transport above). @@ -2086,8 +2112,7 @@ namespace Echoion::Core } } // 3) Legacy file-transfer avatar (async; first call just triggers it). - if (auto p = pluginInterface_->requestClientAvatar(clientId, - "cache/avatars"); + if (auto p = pluginInterface_->requestClientAvatar(clientId, {}); p && p->has_value()) { std::ifstream f(**p, std::ios::binary); if (f) { diff --git a/src/SignatureCipher.cpp b/src/SignatureCipher.cpp index 9e95b58..83400d1 100644 --- a/src/SignatureCipher.cpp +++ b/src/SignatureCipher.cpp @@ -1,12 +1,14 @@ -#include #include "echoion/core/SignatureCipher.hpp" #include -#include +#include +#include #include #include +#include #include #include #include +#include #include // Minimal embedded fallback - a stub that logs errors @@ -492,40 +494,38 @@ namespace Echoion::Core std::optional SignatureCipher::downloadSolverLibrary(std::string_view url) { - // Simple curl-based download with redirect following - // -s: silent, -L: follow redirects, -f: fail on HTTP error, -m 30: - // timeout 30s - std::string cmd = - std::format("curl -sLf -m 30 '{}' 2>&1", std::string(url)); + Void::Log::debug("SignatureCipher", "{}", + std::format("Downloading: {}", url)); - Void::Log::debug("SignatureCipher", "{}", std::format("Downloading: {}", url)); - - FILE* pipe = popen(cmd.c_str(), "r"); - if (!pipe) { - Void::Log::warn("SignatureCipher", "{}", std::format("Failed to run curl for {}", url)); + Void::Net::HttpClient client; + client.set_verify_tls(true); + client.set_max_redirects(5); + client.set_max_body_size(16U * 1024U * 1024U); + Void::Net::Request request; + request.url = std::string(url); + request.method = Void::Net::Method::Get; + request.timeout = std::chrono::seconds{30}; + auto response = client.send(request); + if (!response) { + Void::Log::warn("SignatureCipher", "{}", + std::format("Solver download failed for {}: {}", + url, response.error().message())); + return std::nullopt; + } + if (!response->ok()) { + Void::Log::warn( + "SignatureCipher", "{}", + std::format("Solver download returned HTTP {} for {}", + response->status, url)); + return std::nullopt; + } + if (response->body.empty()) { + Void::Log::warn("SignatureCipher", "{}", + std::format("Downloaded empty file from {}", url)); return std::nullopt; } - std::string result; - char buffer[4096]; - while (fgets(buffer, sizeof(buffer), pipe) != nullptr) { - result += buffer; - } - - int status = pclose(pipe); - if (status != 0) { - Void::Log::warn("SignatureCipher", "{}", - std::format("curl failed with status {} for {}", status, url)); - return std::nullopt; - } - - if (result.empty()) { - Void::Log::warn("SignatureCipher", "{}", - std::format("Downloaded empty file from {}", url)); - return std::nullopt; - } - - return result; + return std::move(response->body); } void SignatureCipher::initSolver() diff --git a/src/YtDlpManager.cpp b/src/YtDlpManager.cpp index 81650ad..d64c8ff 100644 --- a/src/YtDlpManager.cpp +++ b/src/YtDlpManager.cpp @@ -52,6 +52,10 @@ namespace Echoion::Core } return homeDir / "echoion" / "yt-dlp"; #else + if (const char* dataHome = std::getenv("XDG_DATA_HOME"); + dataHome && *dataHome != '\0') { + return std::filesystem::path{dataHome} / "echoion" / "yt-dlp"; + } const char* home = std::getenv("HOME"); if (home) { homeDir = home;