Handle save convert from google drive sync

pull/1/head
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() { async function useRemoteData() {
// 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) { for (const k in remoteSave) {
await updateSave(k, remoteSave[k], true); await updateSave(k, remoteSave[k], true);
} }
}
synced.set(true); synced.set(true);
closeModal(); closeModal();
window.location.reload();
} }
async function useLocalData() { async function useLocalData() {
@ -269,6 +307,7 @@
document.body.appendChild(fileLink); document.body.appendChild(fileLink);
fileLink.click(); fileLink.click();
} }
</script> </script>
<slot /> <slot />

View File

@ -33,6 +33,7 @@
}; };
$: if ($fromRemote) { $: if ($fromRemote) {
console.log('update from google drive');
readLocalData(); 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) { if (convertedCount > 0) {
window.location.reload(); window.location.reload();