Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-16 19:59:45 +03:00
1 parent 39aff68d8d
commit 9f06af6c80
5 files changed
+76 -47

No files matched your search

+4 -4
View File
@@ -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(
+1 -1
View File
@@ -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<void> requireInitialized() const noexcept;
+35 -10
View File
@@ -19,7 +19,9 @@
#include <Void/Log/Sinks.hpp>
#include <Void/Log/SplitFileLogger.hpp>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <filesystem>
#include <format>
#include <fstream>
#include <iomanip>
@@ -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<Void::Logging::MultiLogger> buildLogSink()
[[nodiscard]] std::shared_ptr<Void::Logging::MultiLogger>
buildLogSink(const std::filesystem::path& logDirectory)
{
namespace VL = Void::Logging;
auto multi = std::make_shared<VL::MultiLogger>();
@@ -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<VL::Logger>(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<LyricsService>(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::Database>();
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) {
+32 -32
View File
@@ -1,12 +1,14 @@
#include <Void/Log/Log.hpp>
#include "echoion/core/SignatureCipher.hpp"
#include <Void/Data/Json.hpp>
#include <quickjs.h>
#include <Void/Log/Log.hpp>
#include <Void/Net/Http.hpp>
#include <algorithm>
#include <cctype>
#include <chrono>
#include <filesystem>
#include <format>
#include <fstream>
#include <quickjs.h>
#include <regex>
// Minimal embedded fallback - a stub that logs errors
@@ -492,40 +494,38 @@ namespace Echoion::Core
std::optional<std::string>
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()
+4
View File
@@ -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;