diff --git a/src/index.ts b/src/index.ts index c242238..8112d6a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,17 +12,21 @@ const newPatches: any[] = []; const productData: { [key in Product]?: IProductData } = await model.init(); const productDataEntries = Object.entries(productData) as Array<[Product, IProductData]>; + //Check for new manifest version await Promise.all(productDataEntries.map(async ([product, { manifest, http}]) => { //Check for new manifest version - const { current } = await getManifest(product); - if (current < manifest) { - writeLog(`Product ${product} now has a smaller manifest version ${current}, down from ${manifest}.`); + try { + const { current} = await getManifest(product); + if (current < manifest) { + writeLog(`Product ${product} now has a smaller manifest version ${current}, down from ${manifest}.`); + } else if (current > manifest) { + writeLog(`New manifest version: ${current} instead of ${manifest}`); + model.updateManifestVersion(product, current); + } + } catch (error) { + writeLog(`Could not get manifest for ${product} (previous version was ${manifest}), error message: ${String(error)}`); return; } - if (current > manifest) { - writeLog(`New manifest version: ${current} instead of ${manifest}`); - model.updateManifestVersion(product, current); - } //Check for new HTTP version //TODO diff --git a/src/model/model.ts b/src/model/model.ts index a606c3f..83abba6 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -28,7 +28,8 @@ export async function init(): Promise<{ [key in Product]?: IProductData }> { }); //If row does not exist, INSERT into table - await Promise.all(products.filter((product) => output[product] === undefined).map(function(product) { + const missingProducts = products.filter((product) => output[product] === undefined); + await Promise.all(missingProducts.map(function(product) { output[product] = { http: -1, manifest: -1 }; const queryTemplate = `INSERT INTO \`ssn_versions\` (\`product\`, \`manifest\`, \`http\`) VALUES (?, '-1', '-1');`; const query = mysql.format(queryTemplate, [String(product)]);