mirror of
https://github.com/MadeBaruna/paimon-moe.git
synced 2024-11-27 01:06:29 +01:00
Handle save convert from google drive sync
This commit is contained in:
parent
d165d8161e
commit
084fa3e37c
3 changed files with 45 additions and 3 deletions
|
@ -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 />
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
};
|
||||
|
||||
$: if ($fromRemote) {
|
||||
console.log('update from google drive');
|
||||
readLocalData();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue