From 72fc6ab5b9395202ce9de076eba74ecbd3e1a27b Mon Sep 17 00:00:00 2001 From: Made Baruna Date: Tue, 10 Aug 2021 16:21:15 +0700 Subject: [PATCH] Check conflicting wish history account --- src/components/WishImportModal.svelte | 29 ++++++++++++++++++++++++++- src/locales/en.json | 1 + src/locales/id.json | 1 + src/routes/settings/index.svelte | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/components/WishImportModal.svelte b/src/components/WishImportModal.svelte index 77216d7a..9d981164 100644 --- a/src/components/WishImportModal.svelte +++ b/src/components/WishImportModal.svelte @@ -58,6 +58,7 @@ }, }; + let currentUID = ''; let newOnly = true; let wishes = {}; @@ -96,6 +97,16 @@ } } + async function checkUID() { + const prefix = getAccountPrefix(); + const path = `wish-uid`; + const localData = await readSave(`${prefix}${path}`); + + if (localData !== null) { + currentUID = localData; + } + } + async function startImport() { if (selectedType === 'pclocal') { await importFromGeneratedText(); @@ -119,6 +130,7 @@ } try { + await checkUID(); for (const [wishNumber, type] of Object.entries(types)) { await getLog(wishNumber, type); if (cancelled) return; @@ -227,6 +239,12 @@ const name = row.name; const type = row.item_type.replace(/ /g, ''); + if (currentUID !== '' && currentUID !== row.uid) { + throw 'account error'; + } + + currentUID = row.uid; + if (dayjs(time).isSameOrBefore(newestPullTime)) { return; } @@ -261,7 +279,11 @@ // console.log(wishes); } catch (err) { processingLog = false; - pushToast($t('wish.import.invalidData'), 'error'); + if (err === 'account error') { + pushToast($t('wish.import.differentAccount'), 'error'); + } else { + pushToast($t('wish.import.invalidData'), 'error'); + } console.error(err); throw 'invalid data'; } @@ -407,6 +429,11 @@ const prefix = getAccountPrefix(); await updateSave(`${prefix}collectables-updated`, true); + + if (currentUID !== '') { + await updateSave(`${prefix}wish-uid`, currentUID); + } + closeModal(); } diff --git a/src/locales/en.json b/src/locales/en.json index a406b41a..92a552f6 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -160,6 +160,7 @@ "invalidLink": "Invalid link, please check it again", "errorApi": "Error code returned from MiHoYo API, please try again later!", "timeout": "Connection timeout, please wait a moment and try again later", + "differentAccount": "This wish history is for another account, please separate your account first on Settings menu!", "invalidData": "Invalid data returned from API, try again later", "success": "Import success 😀!", "server": "Select your server:", diff --git a/src/locales/id.json b/src/locales/id.json index c73d810e..ba573238 100644 --- a/src/locales/id.json +++ b/src/locales/id.json @@ -160,6 +160,7 @@ "invalidLink": "Link invalid, silahkan dicek kembali", "errorApi": "Error code dikembalikan dari API MiHoYo, coba lagi nanti!", "timeout": "Connection timeout, tunggu sebentar dan coba lagi nanti", + "differentAccount": "Wish history ini adalah untuk akun lain, pisahkan dulu akun mu di menu Pengaturan!", "invalidData": "Invalid data dikembalikan dari API, coba lagi nanti", "success": "Import berhasil 😀!", "server": "Pilih server mu:", diff --git a/src/routes/settings/index.svelte b/src/routes/settings/index.svelte index d18c458e..b4b43b43 100644 --- a/src/routes/settings/index.svelte +++ b/src/routes/settings/index.svelte @@ -150,6 +150,7 @@ 'wish-counter-weapon-event', 'wish-counter-standard', 'wish-counter-beginners', + 'wish-uid', 'characters', 'achievement', 'collectables-updated', @@ -185,6 +186,7 @@ 'wish-counter-weapon-event', 'wish-counter-standard', 'wish-counter-beginners', + 'wish-uid', 'characters', 'achievement', 'collectables-updated',