🚧 Add preliminary patch downloader

This commit is contained in:
C-3PO 2018-06-23 22:14:55 +02:00
parent 57c99b88fe
commit 3ee23f6445
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
4 changed files with 41 additions and 1 deletions

View file

@ -0,0 +1,18 @@
interface ISolidSimpleFile {
/** Name of this file, e.g. `assets_swtor_de_de_-1to0.z01`. */
name: string;
/** Length of this file in bytes. */
length: number;
}
/** Simplified format of the Bencoded metafile.solid file */
export default interface ISolidSimple {
/** Date and time when this patch was created. */
created: Date;
/** List of files included with this patch (.zip, .z01, etc.) */
files: ISolidSimpleFile[];
/** Length of one piece in bytes, e.g. 4194304 for 4 MiB. */
pieceLength: number;
///** Concatenated hashes of all pieces. */
//pieces: string;
}

21
src/ssn/getPatch.ts Normal file
View file

@ -0,0 +1,21 @@
import getUrlContents from '../cdn/getUrlContents';
import { Product } from '../interfaces/ISettings';
import extractFile from './extractFile';
import getSolidpkg from './getSolidpkg';
import readSsnFile from './readSsnFile';
export default async function getPatch(product: Product, from: number, to: number) {
const solidPkg = await getSolidpkg(product, from, to);
const bufferArray = await Promise.all(solidPkg.files.map((file) => getUrlContents({ host: 'cdn-patch.swtor.com', path: `/patch/${product}/${product}_${from}to${to}/${file.name}` })));
const zipFile = bufferArray[bufferArray.length - 1];
const fileEntries = readSsnFile(zipFile);
//TODO: verify file entries
const dvArray = bufferArray.map((buffer) => new DataView(buffer));
fileEntries.map((entry) => extractFile(entry, dvArray) );
return fileEntries;
}

View file

@ -1,13 +1,14 @@
import getUrlContents from '../cdn/getUrlContents'; import getUrlContents from '../cdn/getUrlContents';
import { Product } from '../interfaces/ISettings'; import { Product } from '../interfaces/ISettings';
import ISolid from '../interfaces/ISolidFile'; import ISolid from '../interfaces/ISolidFile';
import ISolidSimple from '../interfaces/ISolidSimple';
import verifyProductName from '../ssn/verifyProductName'; import verifyProductName from '../ssn/verifyProductName';
import parseBencode from './bencodeParser'; import parseBencode from './bencodeParser';
import extractFile from './extractFile'; import extractFile from './extractFile';
import readSsnFile from './readSsnFile'; import readSsnFile from './readSsnFile';
import verifySolidpkg from './verifySolidpkg'; import verifySolidpkg from './verifySolidpkg';
export default async function getSolidpkg(product: Product, from: number, to: number): Promise<any> { export default async function getSolidpkg(product: Product, from: number, to: number): Promise<ISolidSimple> {
//Verify function arguments //Verify function arguments
if (!verifyProductName(product)) { if (!verifyProductName(product)) {
throw new Error(`"${product}" is not a valid product.`); throw new Error(`"${product}" is not a valid product.`);