Guard source gear namespaces and retain recoverable legacy records (#9)

This commit is contained in:
warren committed 2026-10-10 11:36:10 -04:00
1 parent ab37006932
commit e567910c04
23 files changed
+1203 -66

No files matched your search

+32 -1
View File
@@ -150,6 +150,32 @@ export function retryCloudSave(): void {
if (activeSession) queueCloudSave(activeSession.ownerId, listCharacters(activeSession.ownerId));
}
function gearNamespaceSnapshot(value: unknown): string {
if (!Array.isArray(value)) return "[]";
return JSON.stringify(value.map((candidate) => {
if (!candidate || typeof candidate !== "object" || Array.isArray(candidate)) return candidate;
const character = candidate as Record<string, unknown>;
const rawInventory = character.inventory;
const inventory = Array.isArray(rawInventory)
? rawInventory.map((rawItem) => {
if (!rawItem || typeof rawItem !== "object" || Array.isArray(rawItem)) return rawItem;
const item = rawItem as Record<string, unknown>;
return {
instanceId: item.instanceId,
contentCategory: Object.prototype.hasOwnProperty.call(item, "contentCategory")
? item.contentCategory
: "[missing-content-category]",
};
})
: rawInventory == null ? [] : rawInventory;
return {
id: character.id,
inventory,
gearRecovery: character.gearRecovery ?? null,
};
}));
}
export async function hydrateOnlineSession(session: PlayerSession): Promise<CharacterProfile[]> {
if (!session.accessToken) return listCharacters(session.ownerId);
activateOnlineSession(session);
@@ -163,7 +189,12 @@ export async function hydrateOnlineSession(session: PlayerSession): Promise<Char
suppressUpload = false;
}
// Publish migrated logs even if the player has not earned another card yet.
if (JSON.stringify(cloud.data?.bossCards) !== JSON.stringify(loadAccountBossCards(session.ownerId))) {
const gearNamespaceMigrated = gearNamespaceSnapshot(cloud.data?.characters)
!== gearNamespaceSnapshot(characters);
if (
gearNamespaceMigrated
|| JSON.stringify(cloud.data?.bossCards) !== JSON.stringify(loadAccountBossCards(session.ownerId))
) {
queueCloudSave(session.ownerId, characters);
}
return characters;