From 0f224523d44a0277a046f187c13b9193237ba893 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sun, 8 Jul 2018 23:44:15 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Add=20getSolidPkgZip=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- src/getSolidpkgZip.ts | 33 ++++++++++++++++++++++++++++++ src/ssn/decryption/decryptChunk.ts | 1 - src/ssn/getSolidpkgZip.ts | 26 +++++++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/getSolidpkgZip.ts create mode 100644 src/ssn/getSolidpkgZip.ts diff --git a/README.md b/README.md index 392a2f5..4b6feb1 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ Either directly run whatever script you need: ```bash node dist/getManifest.js assets_swtor_main node dist/getSolidPkg.js assets_swtor_main 126 127 -node dist/installPatch.js +node dist/getSolidPkgZip.js assets_swtor_main 126 127 +node dist/installPatch.js assets_swtor_main 126 127 ``` Or import the functions into your Node.js application: diff --git a/src/getSolidpkgZip.ts b/src/getSolidpkgZip.ts new file mode 100644 index 0000000..dfca06c --- /dev/null +++ b/src/getSolidpkgZip.ts @@ -0,0 +1,33 @@ +import failWithError from './failWithError'; +import { Product } from './interfaces/ISettings'; +import { ISsnFileEntry } from './interfaces/ISsnFileEntry'; +import getSolidpkgZip from './ssn/getSolidpkgZip'; +import verifyProductName from './ssn/verify/verifyProductName'; + +const failFunction = failWithError.bind(null, 'node dist/getSolidpkgZip.js '); + +if (process.argv.length !== 5) { + failFunction(`Expected 3 arguments but ${process.argv.length - 2} arguments were supplied.`); +} + +//Check that product name is valid +const product = process.argv[2]; +if (!verifyProductName(product)) { + failFunction(`"${product.substring(0, 300)}" is not a valid product name.`); +} + +//Check that from and to are valid numbers +const from = process.argv[3]; +const to = process.argv[4]; +if (!from.match(/^(-1|0|[1-9][0-9]{0,2})$/)) { + failFunction(`from value "${from.substring(0, 300)}" is not a valid integer; it must be in range [-1, 999].`); +} +if (!to.match(/^(0|[1-9][0-9]{0,2})$/)) { + failFunction(`to value "${to.substring(0, 300)}" is not a valid integer; it must be in range [0, 999].`); +} + +//Get solidpkg's .zip file and write output to stdout +getSolidpkgZip(product as Product, Number(from), Number(to)).then((output: ISsnFileEntry[]) => { + process.stdout.write(JSON.stringify(output)); + //process.exit(0); +}); diff --git a/src/ssn/decryption/decryptChunk.ts b/src/ssn/decryption/decryptChunk.ts index 4ac5929..8c60509 100644 --- a/src/ssn/decryption/decryptChunk.ts +++ b/src/ssn/decryption/decryptChunk.ts @@ -1,4 +1,3 @@ -import int32Mul from './lib/int32Mul'; import updateKeys from './lib/updateKeys'; export default function getDecryptor(decryptionKeys: [number, number, number]) { diff --git a/src/ssn/getSolidpkgZip.ts b/src/ssn/getSolidpkgZip.ts new file mode 100644 index 0000000..266a2a8 --- /dev/null +++ b/src/ssn/getSolidpkgZip.ts @@ -0,0 +1,26 @@ +import getUrlContents from '../cdn/getUrlContents'; +import { Product } from '../interfaces/ISettings'; +import { ISsnFileEntry } from '../interfaces/ISsnFileEntry'; +import getSolidpkg from './getSolidpkg'; +import readSsnFile from './reader/readSsnFile'; +import verifyPatch from './verify/verifyPatch'; + +export default async function getSolidpkgZip(product: Product, from: number, to: number): Promise { + const solidpkg = await getSolidpkg(product, from, to); + + function createUrlObject({ name, length }: {name: string, length: number}) { + return { host: 'cdn-patch.swtor.com', path: `/patch/${product}/${product}_${from}to${to}/${name}`, size: length }; + } + + //download only last file (the .zip file) + const indexOfLastFile = solidpkg.files.length - 1; + const zipFile = getUrlContents(createUrlObject(solidpkg.files[indexOfLastFile])); + + //parse the file entries when .zip file is downloaded + const fileEntries = readSsnFile(await zipFile); + + //Verify file entries + verifyPatch(fileEntries, product, from); + + return fileEntries; +}