🚀 Add getSolidPkgZip endpoint

This commit is contained in:
C-3PO 2018-07-08 23:44:15 +02:00
parent 40346cadae
commit 0f224523d4
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
4 changed files with 61 additions and 2 deletions

View file

@ -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:

33
src/getSolidpkgZip.ts Normal file
View file

@ -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 <product> <from> <to>');
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);
});

View file

@ -1,4 +1,3 @@
import int32Mul from './lib/int32Mul';
import updateKeys from './lib/updateKeys';
export default function getDecryptor(decryptionKeys: [number, number, number]) {

26
src/ssn/getSolidpkgZip.ts Normal file
View file

@ -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<ISsnFileEntry[]> {
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;
}