Drop the parallel *Json mirror structs and the ~370 LOC of field-by-field
mapping in ConfigLoader and Core. Api::AppConfig is now reflected straight
to/from JSON:
- ConfigLoader::{loadFromFile,saveToFile} use from_json/to_json<AppConfig>
directly; a small normalize() keeps the yt-dlp concurrency cap that the
mapping layer used to enforce.
- Core::{getConfigJson,updateConfigJson} likewise reflect directly, which
also extends them to honor youtube/features/advanced sections that the
old hand-mapping silently dropped.
- parseQuality/qualityToString removed — enums serialize by name.
On-disk format change (v3, clean cutover): durations are strings
("30000ms", also accepts "30s"/"5m"/"1h"), enums are names, the proxy is a
nested object (or null) instead of flat proxyType/proxyHost fields, and the
admin/custom sections now round-trip. Verified: build green, a
serialize->parse->deserialize round-trip of AppConfig (incl. a SOCKS5
proxy) passes, and config.example.json loads through the reflection path.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <ConfigTypes.hpp>
|
|
#include <Types.hpp>
|
|
#include <filesystem>
|
|
#include <string>
|
|
|
|
namespace Echoion::Core
|
|
{
|
|
|
|
// Configuration loader for JSON config files (internal to Core).
|
|
//
|
|
// Api::AppConfig is serialized directly through Void::Json reflection —
|
|
// no mirror DTOs. The on-disk shape follows the domain types: durations
|
|
// are strings ("30000ms"), enums are names ("High"), the proxy is a
|
|
// nested object (or null), and time_points are duration strings.
|
|
class ConfigLoader
|
|
{
|
|
public:
|
|
|
|
// Load configuration from JSON file
|
|
[[nodiscard]] static Api::Result<Api::AppConfig>
|
|
loadFromFile(const std::filesystem::path& path);
|
|
|
|
// Save configuration to JSON file
|
|
[[nodiscard]] static Api::Result<void>
|
|
saveToFile(const std::filesystem::path& path,
|
|
const Api::AppConfig& config);
|
|
|
|
// Get default configuration path
|
|
[[nodiscard]] static std::filesystem::path getDefaultConfigPath();
|
|
|
|
// Create default configuration
|
|
[[nodiscard]] static Api::AppConfig createDefaultConfig();
|
|
|
|
// Clamp/normalize values that carry hard limits after loading
|
|
// (e.g. the yt-dlp concurrency cap). Applied by loadFromFile.
|
|
static void normalize(Api::AppConfig& config);
|
|
};
|
|
|
|
} // namespace Echoion::Core
|