✨ Check for new manifest version
This commit is contained in:
parent
e9a58152d7
commit
334b52f4c6
4 changed files with 44 additions and 12 deletions
30
src/index.ts
30
src/index.ts
|
@ -1,16 +1,36 @@
|
||||||
import { getSolidpkg, Product } from 'ssn';
|
import { getSolidpkg, Product, getManifest } from 'ssn';
|
||||||
import IDatabaseRow from './interfaces/IDatabaseRow';
|
import IProductData from "./interfaces/IProductData";
|
||||||
import * as model from './model/model';
|
import * as model from './model/model';
|
||||||
import * as database from './model/database';
|
import * as database from './model/database';
|
||||||
|
import writeLog from './logger/writeLog';
|
||||||
|
|
||||||
//create lock file to prevent conflicts?
|
//create lock file to prevent conflicts?
|
||||||
|
|
||||||
const newPatches: any[] = [];
|
const newPatches: any[] = [];
|
||||||
|
|
||||||
model.init().then(function(result: any) {
|
(async function() {
|
||||||
console.log(result);
|
const productData: { [key in Product]: IProductData } = await model.init();
|
||||||
|
const productDataEntries = Object.entries(productData) as Array<[Product, IProductData]>;
|
||||||
|
|
||||||
|
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}.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (current > manifest) {
|
||||||
|
writeLog(`New manifest version: ${current} instead of ${manifest}`);
|
||||||
|
model.updateManifestVersion(product, current);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check for new HTTP version
|
||||||
|
//TODO
|
||||||
|
}));
|
||||||
|
|
||||||
database.exit();
|
database.exit();
|
||||||
});
|
}())
|
||||||
|
|
||||||
|
|
||||||
/*//for each product, check new versions
|
/*//for each product, check new versions
|
||||||
Object.entries(products).forEach(([product, { manifestVersion, httpVersion }]: [string, IDatabaseRow]) => {
|
Object.entries(products).forEach(([product, { manifestVersion, httpVersion }]: [string, IDatabaseRow]) => {
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import { Product } from "ssn";
|
import { Product } from "ssn";
|
||||||
|
import IProductData from "./IProductData";
|
||||||
|
|
||||||
export default interface IDatabaseRow {
|
export default interface IDatabaseRow extends IProductData {
|
||||||
/** Name of the product. */
|
/** Name of the product. */
|
||||||
product: Product;
|
product: Product;
|
||||||
/** Latest release number of this product according to the manifest. */
|
|
||||||
manifest: number;
|
|
||||||
/** Latest release number of this product available from the patch server. */
|
|
||||||
http: number;
|
|
||||||
}
|
}
|
||||||
|
|
6
src/interfaces/IProductData.ts
Normal file
6
src/interfaces/IProductData.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
export default interface IProductData {
|
||||||
|
/** Latest release number of this product according to the manifest. */
|
||||||
|
manifest: number;
|
||||||
|
/** Latest release number of this product available from the patch server. */
|
||||||
|
http: number;
|
||||||
|
}
|
|
@ -4,10 +4,15 @@ import products from './products';
|
||||||
import writeLog from '../logger/writeLog';
|
import writeLog from '../logger/writeLog';
|
||||||
import createStatement from './createStatement';
|
import createStatement from './createStatement';
|
||||||
import IDatabaseRow from '../interfaces/IDatabaseRow';
|
import IDatabaseRow from '../interfaces/IDatabaseRow';
|
||||||
|
import IProductData from '../interfaces/IProductData';
|
||||||
|
|
||||||
const state: any = {};
|
const state: any = {};
|
||||||
|
|
||||||
export async function init() {
|
function escapeProduct(product: Product) {
|
||||||
|
return String(product).replace(/'/g, '\\\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function init(): Promise<{ [key in Product]: IProductData }> {
|
||||||
await database.init();
|
await database.init();
|
||||||
|
|
||||||
//Only create table if it does not exist yet
|
//Only create table if it does not exist yet
|
||||||
|
@ -28,8 +33,12 @@ export async function init() {
|
||||||
//If row does not exist, INSERT into table
|
//If row does not exist, INSERT into table
|
||||||
await Promise.all(products.filter((product) => state[product] === undefined).map(function(product) {
|
await Promise.all(products.filter((product) => state[product] === undefined).map(function(product) {
|
||||||
state[product] = { http: -1, manifest: -1 };
|
state[product] = { http: -1, manifest: -1 };
|
||||||
return database.query(`INSERT INTO \`ssn_versions\` (\`product\`, \`manifest\`, \`http\`) VALUES ('${product.replace(/'/g, '\\\'')}', '-1', '-1');`)
|
return database.query(`INSERT INTO \`ssn_versions\` (\`product\`, \`manifest\`, \`http\`) VALUES ('${escapeProduct(product)}', '-1', '-1');`)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateManifestVersion(product: Product, newVersion: number) {
|
||||||
|
return database.query(`UPDATE \`ssn_versions\` SET \`manifest\` = '${Number(newVersion)}' WHERE \`product\` = '${escapeProduct(product)}' COLLATE utf8mb4_bin;`);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue