Skip to content

Commit

Permalink
fix: Added code to help recover in case of manifests failing to download
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimple committed Oct 2, 2021
1 parent c740d63 commit e76cbef
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/scripts/destiny2/apiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -84,6 +84,9 @@ function DestinyApiClient(d2ApiClient) {
resolve({ updatedManifest: true, version: self.lastVersion });
return;
}

await checkStoredDefinitions();

resolve({ updatedManifest: false, version: self.lastVersion });
});
};
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit e76cbef

Please sign in to comment.