🚧 Add preliminary patch downloader
This commit is contained in:
parent
57c99b88fe
commit
3ee23f6445
4 changed files with 41 additions and 1 deletions
18
src/interfaces/ISolidSimple.ts
Normal file
18
src/interfaces/ISolidSimple.ts
Normal 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
21
src/ssn/getPatch.ts
Normal 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;
|
||||||
|
}
|
|
@ -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.`);
|
||||||
|
|
Loading…
Reference in a new issue