Migrate data for offline users
parent
d32dbddd48
commit
adf5690383
|
@ -14,13 +14,22 @@ export function updateUserInfo(): Promise<[boolean, integer]> {
|
||||||
if (bypassLogin) {
|
if (bypassLogin) {
|
||||||
loggedInUser = { username: 'Guest', lastSessionSlot: -1 };
|
loggedInUser = { username: 'Guest', lastSessionSlot: -1 };
|
||||||
let 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}`)) {
|
if (localStorage.getItem(`sessionData${s ? s : ''}_${loggedInUser.username}`)) {
|
||||||
lastSessionSlot = s;
|
lastSessionSlot = s;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loggedInUser.lastSessionSlot = lastSessionSlot;
|
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 ]);
|
return resolve([ true, 200 ]);
|
||||||
}
|
}
|
||||||
Utils.apiFetch('account/info', true).then(response => {
|
Utils.apiFetch('account/info', true).then(response => {
|
||||||
|
|
|
@ -355,7 +355,6 @@ export class GameData {
|
||||||
|
|
||||||
if (cachedSystemDataStr) {
|
if (cachedSystemDataStr) {
|
||||||
let cachedSystemData = this.parseSystemData(cachedSystemDataStr);
|
let cachedSystemData = this.parseSystemData(cachedSystemDataStr);
|
||||||
console.log(cachedSystemData.timestamp, systemData.timestamp)
|
|
||||||
if (cachedSystemData.timestamp > systemData.timestamp) {
|
if (cachedSystemData.timestamp > systemData.timestamp) {
|
||||||
console.debug('Use cached system');
|
console.debug('Use cached system');
|
||||||
systemData = cachedSystemData;
|
systemData = cachedSystemData;
|
||||||
|
|
Loading…
Reference in New Issue