diff --git a/src/getConfig.ts b/src/getConfig.ts deleted file mode 100644 index 5023a51..0000000 --- a/src/getConfig.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Product } from 'ssn'; -import IProductData from './interfaces/IProductData'; - -const data: { [key in Product]: IProductData } = { - assets_swtor_main: { manifestVersion: 294, httpVersion: 294 }, - assets_swtor_de_de: { manifestVersion: 297, httpVersion: 297 }, - assets_swtor_en_us: { manifestVersion: 299, httpVersion: 299 }, - assets_swtor_fr_fr: { manifestVersion: 299, httpVersion: 299 }, - assets_swtor_test_main: { manifestVersion: 292, httpVersion: 292 }, - assets_swtor_test_de_de: { manifestVersion: 295, httpVersion: 295 }, - assets_swtor_test_en_us: { manifestVersion: 295, httpVersion: 295 }, - assets_swtor_test_fr_fr: { manifestVersion: 295, httpVersion: 295 }, - retailclient_swtor: { manifestVersion: 247, httpVersion: 247 }, - retailclient_publictest: { manifestVersion: 269, httpVersion: 269 }, - retailclient_betatest: { manifestVersion: 13, httpVersion: 13 }, - retailclient_liveqatest: { manifestVersion: 203, httpVersion: 205 }, - retailclient_liveeptest: { manifestVersion: 133, httpVersion: 199 }, - retailclient_cstraining: { manifestVersion: 141, httpVersion: 141 }, - retailclient_squadron157: { manifestVersion: 11, httpVersion: -1 }, - eualas: { manifestVersion: 0, httpVersion: 0 }, - patcher2014: { manifestVersion: 8, httpVersion: 7 }, - patcher2017: { manifestVersion: 0, httpVersion: 0 }, - movies_de_de: { manifestVersion: 5, httpVersion: 5 }, - movies_en_us: { manifestVersion: 5, httpVersion: 5 }, - movies_fr_fr: { manifestVersion: 5, httpVersion: 5 }, -}; - -export default data; diff --git a/src/index.ts b/src/index.ts index d625d6b..8e4ecfd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,5 @@ import { getSolidpkg, Product } from 'ssn'; -import products from './getConfig'; -import IProductData from './interfaces/IProductData'; +import IDatabaseRow from './interfaces/IDatabaseRow'; import * as model from './model/model'; import * as database from './model/database'; @@ -8,12 +7,13 @@ import * as database from './model/database'; const newPatches: any[] = []; -model.init().then(() => { +model.init().then(function(result: any) { + console.log(result); database.exit(); }); /*//for each product, check new versions -Object.entries(products).forEach(([product, { manifestVersion, httpVersion }]: [string, IProductData]) => { +Object.entries(products).forEach(([product, { manifestVersion, httpVersion }]: [string, IDatabaseRow]) => { const curVersion = 100; //Check patch to next release for (let i = curVersion; i < curVersion + 3; i += 1) { diff --git a/src/interfaces/IDatabaseRow.ts b/src/interfaces/IDatabaseRow.ts new file mode 100644 index 0000000..f6ae5d5 --- /dev/null +++ b/src/interfaces/IDatabaseRow.ts @@ -0,0 +1,10 @@ +import { Product } from "ssn"; + +export default interface IDatabaseRow { + /** Name of the 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; +} diff --git a/src/interfaces/IProductData.ts b/src/interfaces/IProductData.ts deleted file mode 100644 index 6fbdbdb..0000000 --- a/src/interfaces/IProductData.ts +++ /dev/null @@ -1,6 +0,0 @@ -export default interface IProductData { - /** Latest release number of this product according to manifest. */ - manifestVersion: number; - /** Latest release number of this product available from the patch server. */ - httpVersion: number; -} diff --git a/src/model/model.ts b/src/model/model.ts index 994b5fe..10ed3d2 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -3,6 +3,9 @@ import * as database from './database'; import products from './products'; import writeLog from '../logger/writeLog'; import createStatement from './createStatement'; +import IDatabaseRow from '../interfaces/IDatabaseRow'; + +const state: any = {}; export async function init() { await database.init(); @@ -11,29 +14,22 @@ export async function init() { const createIfNotExists = createStatement.replace(/^CREATE TABLE/, 'CREATE TABLE IF NOT EXISTS'); await database.query(createIfNotExists); - /**Products that are missing from the database and need to be inserted. */ - const missingProducts: Product[] = []; - /** Products inside the database table that are not valid products. Will be printed to error log and ignored */ - const erroneousProducts: Product[] = []; + const { results: existingRows }: { results: IDatabaseRow[]} = await database.query('SELECT * FROM ssn_versions'); - const { results: existingRows } = await database.query('SELECT * FROM ssn_versions'); - console.log(existingRows); - return; + existingRows.forEach(function(row: IDatabaseRow) { + if (!products.includes(row.product)) { + writeLog(`Product ${row.product} in database table is invalid.`); + return; + } - existingRows.forEach((row: any) => { - //TODO: match with products + state[row.product] = { http: row.http, manifest: row.manifest }; }); //If row does not exist, INSERT into table - await Promise.all(missingProducts.map((product) => { - return database.query(`INSERT INTO ssn_versions ${product}`); + await Promise.all(products.filter((product) => state[product] === undefined).map(function(product) { + state[product] = { http: -1, manifest: -1 }; + return database.query(`INSERT INTO \`ssn_versions\` (\`product\`, \`manifest\`, \`http\`) VALUES ('${product.replace(/'/g, '\\\'')}', '-1', '-1');`) })); - //If row exists that is not in products, ignore it and output error - erroneousProducts.forEach((product) => { - writeLog(`Product ${product} in database table is invalid.`); - }); - - //TODO: insert products - + return state; }