1 parent
39aff68d8d
commit
9f06af6c80
5 files changed
+72
-43
No files matched your search
+4
-4
@@ -41,10 +41,10 @@ target_link_libraries(EchoionCore PUBLIC
|
|||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET
|
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET
|
||||||
libavformat
|
libavformat>=59
|
||||||
libavcodec
|
libavcodec>=59
|
||||||
libswresample
|
libswresample>=4
|
||||||
libavutil
|
libavutil>=57
|
||||||
)
|
)
|
||||||
|
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ namespace Echoion::Core
|
|||||||
|
|
||||||
// Build the console + split-file logging stack and install it as
|
// Build the console + split-file logging stack and install it as
|
||||||
// the global Void::Log sink (logSink_ must outlive logging).
|
// 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.
|
// Guard helper: ok if initialized, else a ServiceUnavailable error.
|
||||||
[[nodiscard]] Api::Result<void> requireInitialized() const noexcept;
|
[[nodiscard]] Api::Result<void> requireInitialized() const noexcept;
|
||||||
|
|||||||
+35
-10
@@ -19,7 +19,9 @@
|
|||||||
#include <Void/Log/Sinks.hpp>
|
#include <Void/Log/Sinks.hpp>
|
||||||
#include <Void/Log/SplitFileLogger.hpp>
|
#include <Void/Log/SplitFileLogger.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstdlib>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <filesystem>
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@@ -31,6 +33,16 @@ namespace Echoion::Core
|
|||||||
{
|
{
|
||||||
namespace
|
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
|
// Decode cached avatar bytes before serving them over HTTP. Returns
|
||||||
// empty on malformed input.
|
// empty on malformed input.
|
||||||
#ifdef ECHOION_WITH_WEB
|
#ifdef ECHOION_WITH_WEB
|
||||||
@@ -140,7 +152,8 @@ namespace Echoion::Core
|
|||||||
// Build the console + split-file logging stack and install it as the
|
// Build the console + split-file logging stack and install it as the
|
||||||
// process-wide Void::Log sink. Replaces the old ILogger/LoggerRegistry
|
// process-wide Void::Log sink. Replaces the old ILogger/LoggerRegistry
|
||||||
// indirection; every ECHOION_LOG_* macro is now a Void::Log:: call.
|
// 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;
|
namespace VL = Void::Logging;
|
||||||
auto multi = std::make_shared<VL::MultiLogger>();
|
auto multi = std::make_shared<VL::MultiLogger>();
|
||||||
@@ -155,7 +168,7 @@ namespace Echoion::Core
|
|||||||
opts.combined = true;
|
opts.combined = true;
|
||||||
opts.max_bytes = 10 * 1024 * 1024;
|
opts.max_bytes = 10 * 1024 * 1024;
|
||||||
opts.max_files = 5;
|
opts.max_files = 5;
|
||||||
if (auto fileSink = VL::SplitFileLogger::open("logs", opts)) {
|
if (auto fileSink = VL::SplitFileLogger::open(logDirectory, opts)) {
|
||||||
(*fileSink)->set_formatter(formatter);
|
(*fileSink)->set_formatter(formatter);
|
||||||
multi->add(std::shared_ptr<VL::Logger>(std::move(*fileSink)));
|
multi->add(std::shared_ptr<VL::Logger>(std::move(*fileSink)));
|
||||||
}
|
}
|
||||||
@@ -179,9 +192,9 @@ namespace Echoion::Core
|
|||||||
|
|
||||||
Core::Core() = default;
|
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_sink(Void::Log::make_sink(logSink_));
|
||||||
Void::Log::set_min_level(Void::Log::Level::Debug);
|
Void::Log::set_min_level(Void::Log::Level::Debug);
|
||||||
}
|
}
|
||||||
@@ -213,9 +226,18 @@ namespace Echoion::Core
|
|||||||
return Api::fail(Api::ErrorCode::AlreadyExists,
|
return Api::fail(Api::ErrorCode::AlreadyExists,
|
||||||
"Core already initialized");
|
"Core already initialized");
|
||||||
}
|
}
|
||||||
installLogging();
|
|
||||||
// Store config path for later reload
|
// Store config path for later reload
|
||||||
configPath_ = configPath;
|
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
|
// Load config from file (Core-internal, Plugin doesn't need to know
|
||||||
// about AppConfig structure)
|
// about AppConfig structure)
|
||||||
@@ -265,10 +287,14 @@ namespace Echoion::Core
|
|||||||
// Lyrics provider (lrclib) — shares the proxy-aware network client.
|
// Lyrics provider (lrclib) — shares the proxy-aware network client.
|
||||||
lyricsService_ = std::make_shared<LyricsService>(networkClient_);
|
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>();
|
database_ = std::make_shared<Api::Database>();
|
||||||
Api::DatabaseConfig dbConfig;
|
Api::DatabaseConfig dbConfig;
|
||||||
dbConfig.path = configPath.parent_path() / "echoion.db";
|
dbConfig.path = stateDir / "echoion.db";
|
||||||
auto dbResult = database_->initialize(dbConfig);
|
auto dbResult = database_->initialize(dbConfig);
|
||||||
if (!dbResult) {
|
if (!dbResult) {
|
||||||
Void::Log::warn("Core", "{}",
|
Void::Log::warn("Core", "{}",
|
||||||
@@ -496,7 +522,7 @@ namespace Echoion::Core
|
|||||||
server->broadcastEvent("plugins.updated", "{}");
|
server->broadcastEvent("plugins.updated", "{}");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
extensionPlugins_->loadDirectory(configPath.parent_path() / "plugins");
|
extensionPlugins_->loadDirectory(stateDir / "plugins");
|
||||||
|
|
||||||
#ifdef ECHOION_WITH_WEB
|
#ifdef ECHOION_WITH_WEB
|
||||||
// Browser web interface (independent of the RPC transport above).
|
// 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).
|
// 3) Legacy file-transfer avatar (async; first call just triggers it).
|
||||||
if (auto p = pluginInterface_->requestClientAvatar(clientId,
|
if (auto p = pluginInterface_->requestClientAvatar(clientId, {});
|
||||||
"cache/avatars");
|
|
||||||
p && p->has_value()) {
|
p && p->has_value()) {
|
||||||
std::ifstream f(**p, std::ios::binary);
|
std::ifstream f(**p, std::ios::binary);
|
||||||
if (f) {
|
if (f) {
|
||||||
|
|||||||
+28
-28
@@ -1,12 +1,14 @@
|
|||||||
#include <Void/Log/Log.hpp>
|
|
||||||
#include "echoion/core/SignatureCipher.hpp"
|
#include "echoion/core/SignatureCipher.hpp"
|
||||||
#include <Void/Data/Json.hpp>
|
#include <Void/Data/Json.hpp>
|
||||||
#include <quickjs.h>
|
#include <Void/Log/Log.hpp>
|
||||||
|
#include <Void/Net/Http.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <chrono>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <quickjs.h>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
// Minimal embedded fallback - a stub that logs errors
|
// Minimal embedded fallback - a stub that logs errors
|
||||||
@@ -492,40 +494,38 @@ namespace Echoion::Core
|
|||||||
std::optional<std::string>
|
std::optional<std::string>
|
||||||
SignatureCipher::downloadSolverLibrary(std::string_view url)
|
SignatureCipher::downloadSolverLibrary(std::string_view url)
|
||||||
{
|
{
|
||||||
// Simple curl-based download with redirect following
|
Void::Log::debug("SignatureCipher", "{}",
|
||||||
// -s: silent, -L: follow redirects, -f: fail on HTTP error, -m 30:
|
std::format("Downloading: {}", url));
|
||||||
// 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::Net::HttpClient client;
|
||||||
|
client.set_verify_tls(true);
|
||||||
FILE* pipe = popen(cmd.c_str(), "r");
|
client.set_max_redirects(5);
|
||||||
if (!pipe) {
|
client.set_max_body_size(16U * 1024U * 1024U);
|
||||||
Void::Log::warn("SignatureCipher", "{}", std::format("Failed to run curl for {}", url));
|
Void::Net::Request request;
|
||||||
return std::nullopt;
|
request.url = std::string(url);
|
||||||
}
|
request.method = Void::Net::Method::Get;
|
||||||
|
request.timeout = std::chrono::seconds{30};
|
||||||
std::string result;
|
auto response = client.send(request);
|
||||||
char buffer[4096];
|
if (!response) {
|
||||||
while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
|
|
||||||
result += buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
int status = pclose(pipe);
|
|
||||||
if (status != 0) {
|
|
||||||
Void::Log::warn("SignatureCipher", "{}",
|
Void::Log::warn("SignatureCipher", "{}",
|
||||||
std::format("curl failed with status {} for {}", status, url));
|
std::format("Solver download failed for {}: {}",
|
||||||
|
url, response.error().message()));
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
if (!response->ok()) {
|
||||||
if (result.empty()) {
|
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", "{}",
|
Void::Log::warn("SignatureCipher", "{}",
|
||||||
std::format("Downloaded empty file from {}", url));
|
std::format("Downloaded empty file from {}", url));
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return std::move(response->body);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SignatureCipher::initSolver()
|
void SignatureCipher::initSolver()
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ namespace Echoion::Core
|
|||||||
}
|
}
|
||||||
return homeDir / "echoion" / "yt-dlp";
|
return homeDir / "echoion" / "yt-dlp";
|
||||||
#else
|
#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");
|
const char* home = std::getenv("HOME");
|
||||||
if (home) {
|
if (home) {
|
||||||
homeDir = home;
|
homeDir = home;
|
||||||
|
|||||||
Reference in new issue
Block a user