Files
EchoionCore/src/state/StateMigration.cpp
T
faumarayandClaude Opus 4.8 f8757d6040 Inline 4 trivial Void delegation shims
Remove YouTubeClient::urlEncode/decodeHtmlEntities/parseIso8601Duration and
StateSerializer::getCurrentTimestampISO8601 — each just forwarded to one Void
call — and have the ~12 call sites call Void directly
(Void::Encoding::Url::encode, Void::Text::html_unescape,
Void::Time::parse_iso8601_interval(...).value_or(0), Void::Time::utc_now_iso8601).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 22:04:43 +03:00

75 lines
2.0 KiB
C++

#include "echoion/core/state/StateMigration.hpp"
#include "echoion/core/state/StateSerializer.hpp"
#include <Void/Data/Json.hpp>
#include <Void/Data/Reflect.hpp>
#include <Void/Time/Format.hpp>
#include <format>
namespace Echoion::Core
{
Api::Result<StateV1> StateMigration::migrate(uint32_t fromVersion,
const std::string& jsonData)
{
// Migration chain: fromVersion -> ... -> CURRENT_VERSION
// For now, only V0 -> V1 is implemented
// Future: V1 -> V2, V2 -> V3, etc.
if (fromVersion == 0) {
auto parsed = Void::Json::parse(jsonData);
if (!parsed) {
return std::unexpected(Api::Error{Api::ErrorCode::ParseError,
"Failed to parse V0 state"});
}
auto v0 = Void::Json::from_json<StateV0>(*parsed);
if (!v0) {
return std::unexpected(Api::Error{Api::ErrorCode::ParseError,
"Failed to parse V0 state"});
}
return fromV0(*v0);
}
// Add more migrations here as versions evolve
// if (fromVersion == 1) { return fromV1(...); }
return std::unexpected(Api::Error{
Api::ErrorCode::IncompatibleVersion,
std::format("No migration path from version {}", fromVersion)});
}
StateV1 StateMigration::fromV0(const StateV0& v0)
{
StateV1 v1;
// Migrate queue
for (const auto& trackId : v0.trackIds) {
StateV1::QueueEntryState entry;
entry.track.id = trackId;
entry.track.title = "Unknown";
entry.track.artist = "Unknown";
v1.queue.push_back(std::move(entry));
}
// Migrate playback state
if (!v1.queue.empty()) {
StateV1::PlaybackState playback;
playback.currentTrack = v1.queue[0].track;
playback.volume = v0.volume;
v1.playback = std::move(playback);
v1.hasPlayback = true;
}
v1.version = 1;
v1.savedAt = Void::Time::utc_now_iso8601();
return v1;
}
bool StateMigration::canMigrate(uint32_t fromVersion)
{
return fromVersion >= StateSerializer::getMinimumSupportedVersion() &&
fromVersion < StateSerializer::getCurrentVersion();
}
} // namespace Echoion::Core