From e76cbefcd34441c0108772521a0a7094fc7732f5 Mon Sep 17 00:00:00 2001 From: NoLifeKing Date: Sat, 2 Oct 2021 08:09:24 +0200 Subject: [PATCH] fix: Added code to help recover in case of manifests failing to download --- src/scripts/destiny2/apiClient.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/scripts/destiny2/apiClient.js b/src/scripts/destiny2/apiClient.js index 40758ec..b60af81 100644 --- a/src/scripts/destiny2/apiClient.js +++ b/src/scripts/destiny2/apiClient.js @@ -75,7 +75,7 @@ function DestinyApiClient(d2ApiClient) { self.cachedManifest = manifest.Response; - await db.setItem("manifestVersion", self.lastVersion); + await db.setItem("manifestVersion", manifest.Response.version); await db.setItem("manifest", JSON.stringify(self.cachedManifest)); await db.setItem("lastManifestUpdate", Date.now()); @@ -84,6 +84,9 @@ function DestinyApiClient(d2ApiClient) { resolve({ updatedManifest: true, version: self.lastVersion }); return; } + + await checkStoredDefinitions(); + resolve({ updatedManifest: false, version: self.lastVersion }); }); }; @@ -139,6 +142,8 @@ function DestinyApiClient(d2ApiClient) { self.lastVersion = await db.getItem("manifestVersion"); } + await checkStoredDefinitions(); + for (let dataType of destinyDataTypes) { let data = await db.getItem(`destinyContent-${dataType}`); if (data !== null) { @@ -159,6 +164,24 @@ function DestinyApiClient(d2ApiClient) { eventEmitter.emit("destiny-data-loaded"); } + async function checkStoredDefinitions() { + let missingDefinitions = []; + + for (let dataType of destinyDataTypes) { + if ((await db.getItem(`destinyContent-${dataType}`)) === null) { + missingDefinitions.push(dataType); + } + } + + if (missingDefinitions.length > 0) { + for (let dataType of destinyDataTypes) { + await db.removeItem(`destinyContent-${dataType}`); + } + + await self.loadDestinyContentData(); + } + } + this.loadDestinyContentData = async function () { for (let dataType of destinyDataTypes) { await loadDestinyContentDataType(dataType);