Serialize AppConfig directly via Void::Json reflection
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>
This commit is contained in:
1 parent
a9ab0d6b75
commit
51f1651c18
3 files changed
+31
-477
No files matched your search
@@ -8,101 +8,12 @@
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
// JSON structures for configuration (public for use by Core)
|
||||
struct BotConfigJson {
|
||||
std::string botName = "Echoion";
|
||||
std::string commandPrefix = "!";
|
||||
float defaultVolume = 0.5f;
|
||||
uint32_t maxQueueSize = 100;
|
||||
uint32_t trackTimeout = 30000;
|
||||
bool autoReconnect = true;
|
||||
uint32_t reconnectDelay = 5000;
|
||||
uint32_t maxReconnectAttempts = 5;
|
||||
std::string preferredQuality = "High";
|
||||
bool allowPlaylistImports = true;
|
||||
};
|
||||
|
||||
struct YouTubeConfigJson {
|
||||
std::optional<std::string> youtubeApiKey;
|
||||
std::optional<std::string> youtubeCookiesPath;
|
||||
std::optional<std::string> cookiesFromBrowser;
|
||||
uint32_t ytDlpMaxConcurrent = 4;
|
||||
bool ytDlpAsyncEnabled = true;
|
||||
bool enableUrlShortening = true;
|
||||
};
|
||||
|
||||
struct NetworkConfigJson {
|
||||
// Proxy settings (flat structure for backward compatibility)
|
||||
std::string proxyType = "HTTP";
|
||||
std::optional<std::string> proxyHost;
|
||||
std::optional<uint16_t> proxyPort;
|
||||
std::optional<std::string> proxyUsername;
|
||||
std::optional<std::string> proxyPassword;
|
||||
// RPC settings
|
||||
bool rpcEnabled = true;
|
||||
uint16_t rpcPort = 8765;
|
||||
std::string rpcBindAddress = "127.0.0.1";
|
||||
};
|
||||
|
||||
struct TeamSpeakConfigJson {
|
||||
std::string address = "localhost";
|
||||
uint16_t port = 9987;
|
||||
std::string serverPassword = "";
|
||||
std::string nickname = "EchoionBot";
|
||||
std::optional<std::string> defaultChannelId;
|
||||
std::optional<std::string> channelPassword;
|
||||
std::vector<uint64_t> adminGroups;
|
||||
std::vector<uint64_t> djGroups;
|
||||
std::vector<uint64_t> bannedGroups;
|
||||
};
|
||||
|
||||
struct SecurityConfigJson {
|
||||
bool requireAuthForAdmin = true;
|
||||
uint32_t maxLoginAttempts = 5;
|
||||
uint32_t lockoutDuration = 300000;
|
||||
uint32_t sessionTimeout = 3600000;
|
||||
bool enableAuditLog = true;
|
||||
std::optional<std::string> apiKey;
|
||||
bool allowCors = false;
|
||||
std::vector<std::string> corsOrigins;
|
||||
};
|
||||
|
||||
struct FeaturesConfigJson {
|
||||
bool enableHotReload = true;
|
||||
bool enableAutoReload = false;
|
||||
bool enableAutoUpdateCheck = true;
|
||||
bool autoStartOnSubscribe = true;
|
||||
bool pauseOnEmptySubscribers = true;
|
||||
bool resumeOnSubscriberReturn = true;
|
||||
std::string shuffleMode = "random";
|
||||
std::string repeatMode = "off";
|
||||
uint32_t maxHistorySize = 50;
|
||||
};
|
||||
|
||||
struct AdvancedConfigJson {
|
||||
uint32_t sampleRate = 192000;
|
||||
uint32_t channels = 2;
|
||||
uint32_t bufferSize = 7680;
|
||||
uint32_t commandThreadPoolSize = 4;
|
||||
uint32_t networkThreadPoolSize = 4;
|
||||
uint32_t decoderThreads = 2;
|
||||
bool cacheEnabled = true;
|
||||
std::string cacheMaxSize = "1GB";
|
||||
uint32_t cacheTTL = 86400;
|
||||
uint32_t tempCleanupInterval = 3600;
|
||||
};
|
||||
|
||||
struct AppConfigJson {
|
||||
BotConfigJson bot;
|
||||
YouTubeConfigJson youtube;
|
||||
NetworkConfigJson network;
|
||||
TeamSpeakConfigJson teamspeak;
|
||||
SecurityConfigJson security;
|
||||
FeaturesConfigJson features;
|
||||
AdvancedConfigJson advanced;
|
||||
};
|
||||
|
||||
// Configuration loader for JSON config files (internal to 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:
|
||||
@@ -122,11 +33,9 @@ namespace Echoion::Core
|
||||
// Create default configuration
|
||||
[[nodiscard]] static Api::AppConfig createDefaultConfig();
|
||||
|
||||
// Parse quality string to enum
|
||||
[[nodiscard]] static Api::AudioQuality
|
||||
parseQuality(const std::string& str);
|
||||
[[nodiscard]] static std::string
|
||||
qualityToString(Api::AudioQuality quality);
|
||||
// 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
|
||||
Reference in new issue
Block a user