Handle save convert from google drive sync

This commit is contained in:
Made Baruna 2021-05-18 17:50:37 +08:00
parent d165d8161e
commit 084fa3e37c
No known key found for this signature in database
GPG key ID: 5AA5DA16AA5DCEAD
3 changed files with 45 additions and 3 deletions

View file

@ -89,13 +89,51 @@
}
}
function convertTime(data) {
for (const pull of data.pulls) {
pull.time = dayjs.unix(pull.time).format('YYYY-MM-DD HH:mm:ss');
}
return data;
}
async function useRemoteData() {
for (const k in remoteSave) {
await updateSave(k, remoteSave[k], true);
// check if old local storage version
if (remoteSave['converted'] === undefined) {
for (const key in remoteSave) {
if (key.endsWith('ar') || key.endsWith('wl')) {
await updateSave(key, Number(remoteSave[key]), true);
} else if (key.endsWith('collectables-updated')) {
await updateSave(key, remoteSave[key] === 'true', true);
} else if (
key.endsWith('accounts') ||
key.endsWith('locale') ||
key.endsWith('server') ||
key.endsWith('update-time')
) {
await updateSave(key, remoteSave[key], true);
} else if (
key.endsWith('wish-counter-character-event') ||
key.endsWith('wish-counter-weapon-event') ||
key.endsWith('wish-counter-standard') ||
key.endsWith('wish-counter-beginners')
) {
const converted = convertTime(JSON.parse(remoteSave[key]));
await updateSave(key, converted, true);
} else {
await updateSave(key, JSON.parse(remoteSave[key]), true);
}
}
console.log('finished convert from google drive');
} else {
for (const k in remoteSave) {
await updateSave(k, remoteSave[k], true);
}
}
synced.set(true);
closeModal();
window.location.reload();
}
async function useLocalData() {
@ -269,6 +307,7 @@
document.body.appendChild(fileLink);
fileLink.click();
}
</script>
<slot />

View file

@ -33,6 +33,7 @@
};
$: if ($fromRemote) {
console.log('update from google drive');
readLocalData();
}

View file

@ -101,7 +101,9 @@ const convertSave = async () => {
}
}
localStorage.setItem(CONVERTED_KEY, dayjs().toISOString());
const convertedTime = dayjs().toISOString();
localStorage.setItem(CONVERTED_KEY, convertedTime);
await localforage.setItem(CONVERTED_KEY, convertedTime);
if (convertedCount > 0) {
window.location.reload();