Migrate data for offline users

pull/912/head
Flashfyre 2024-05-15 10:55:17 -04:00
parent d32dbddd48
commit adf5690383
2 changed files with 10 additions and 2 deletions

View File

@ -14,13 +14,22 @@ export function updateUserInfo(): Promise<[boolean, integer]> {
if (bypassLogin) {
loggedInUser = { username: 'Guest', lastSessionSlot: -1 };
let lastSessionSlot = -1;
for (let s = 0; s < 2; s++) {
for (let s = 0; s < 5; s++) {
if (localStorage.getItem(`sessionData${s ? s : ''}_${loggedInUser.username}`)) {
lastSessionSlot = s;
break;
}
}
loggedInUser.lastSessionSlot = lastSessionSlot;
// Migrate old data from before the username was appended
[ 'data', 'sessionData', 'sessionData1', 'sessionData2', 'sessionData3', 'sessionData4' ].map(d => {
if (localStorage.hasOwnProperty(d)) {
if (localStorage.hasOwnProperty(`${d}_${loggedInUser.username}`))
localStorage.setItem(`${d}_${loggedInUser.username}_bak`, localStorage.getItem(`${d}_${loggedInUser.username}`));
localStorage.setItem(`${d}_${loggedInUser.username}`, localStorage.getItem(d));
localStorage.removeItem(d);
}
});
return resolve([ true, 200 ]);
}
Utils.apiFetch('account/info', true).then(response => {

View File

@ -355,7 +355,6 @@ export class GameData {
if (cachedSystemDataStr) {
let cachedSystemData = this.parseSystemData(cachedSystemDataStr);
console.log(cachedSystemData.timestamp, systemData.timestamp)
if (cachedSystemData.timestamp > systemData.timestamp) {
console.debug('Use cached system');
systemData = cachedSystemData;