🎨 Improve file download and typescript annotations
This commit is contained in:
parent
b502075cb3
commit
8424ae8978
5 changed files with 53 additions and 65 deletions
|
@ -1,12 +1,6 @@
|
||||||
interface ISettings {
|
import { ISettings, Product } from './interfaces/ISettings';
|
||||||
[key: string]: any;
|
|
||||||
product?: 'assets_swtor_de_de' | 'assets_swtor_en_us' | 'assets_swtor_fr_fr' | 'assets_swtor_main' | 'assets_swtor_test_de_de' | 'assets_swtor_test_en_us' | 'assets_swtor_test_fr_fr' | 'assets_swtor_test_main' | 'eualas' | 'movies_de_de' | 'movies_en_us' | 'movies_fr_fr' | 'patcher2014' | 'patcher2017' | 'retailclient_betatest' | 'retailclient_cstraining' | 'retailclient_liveeptest' | 'retailclient_publictest' | 'retailclient_squadron157' | 'retailclient_swtor';
|
|
||||||
release?: number; //TODO: allow 'current', but how will we know what current version is?
|
|
||||||
from?: number;
|
|
||||||
outputType?: 'info' | 'file'; //whether to just show JSON information, or actually write files into a directory
|
|
||||||
}
|
|
||||||
|
|
||||||
const allowedProducts: Array<ISettings['product']> = ['assets_swtor_de_de', 'assets_swtor_en_us', 'assets_swtor_fr_fr', 'assets_swtor_main', 'assets_swtor_test_de_de', 'assets_swtor_test_en_us', 'assets_swtor_test_fr_fr', 'assets_swtor_test_main', 'eualas', 'movies_de_de', 'movies_en_us', 'movies_fr_fr', 'patcher2014', 'patcher2017', 'retailclient_betatest', 'retailclient_cstraining', 'retailclient_liveeptest', 'retailclient_publictest', 'retailclient_squadron157', 'retailclient_swtor'];
|
const allowedProducts: Product[] = ['assets_swtor_de_de', 'assets_swtor_en_us', 'assets_swtor_fr_fr', 'assets_swtor_main', 'assets_swtor_test_de_de', 'assets_swtor_test_en_us', 'assets_swtor_test_fr_fr', 'assets_swtor_test_main', 'eualas', 'movies_de_de', 'movies_en_us', 'movies_fr_fr', 'patcher2014', 'patcher2017', 'retailclient_betatest', 'retailclient_cstraining', 'retailclient_liveeptest', 'retailclient_publictest', 'retailclient_squadron157', 'retailclient_swtor'];
|
||||||
|
|
||||||
const settings: ISettings = {};
|
const settings: ISettings = {};
|
||||||
|
|
||||||
|
@ -16,8 +10,8 @@ export const set = (key: string, value: any) => {
|
||||||
case 'product':
|
case 'product':
|
||||||
//TODO: need to verify input (one of allowed products)
|
//TODO: need to verify input (one of allowed products)
|
||||||
if (typeof value !== 'string') { throw new Error(`product must be a string but it's a "${typeof value}".`); }
|
if (typeof value !== 'string') { throw new Error(`product must be a string but it's a "${typeof value}".`); }
|
||||||
if (!allowedProducts.includes(value as ISettings['product'])) { throw new Error(`"${value}" is not an allowed product.`); }
|
if (!allowedProducts.includes(value as Product)) { throw new Error(`"${value}" is not an allowed product.`); }
|
||||||
settings.product = value as ISettings['product'];
|
settings.product = value as Product;
|
||||||
break;
|
break;
|
||||||
case 'release':
|
case 'release':
|
||||||
//verify input (must be a number >=0, and >settings.from)
|
//verify input (must be a number >=0, and >settings.from)
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
export const enum Releases {
|
|
||||||
'assets_swtor_de_de',
|
|
||||||
'assets_swtor_en_us',
|
|
||||||
'assets_swtor_fr_fr',
|
|
||||||
'assets_swtor_main',
|
|
||||||
'assets_swtor_test_de_de',
|
|
||||||
'assets_swtor_test_en_us',
|
|
||||||
'assets_swtor_test_fr_fr',
|
|
||||||
'assets_swtor_test_main',
|
|
||||||
'eualas',
|
|
||||||
'movies_de_de',
|
|
||||||
'movies_en_us',
|
|
||||||
'movies_fr_fr',
|
|
||||||
'patcher2014',
|
|
||||||
'patcher2017',
|
|
||||||
'retailclient_betatest',
|
|
||||||
'retailclient_cstraining',
|
|
||||||
'retailclient_liveeptest',
|
|
||||||
'retailclient_publictest',
|
|
||||||
'retailclient_squadron157',
|
|
||||||
'retailclient_swtor',
|
|
||||||
};
|
|
|
@ -1,10 +1,10 @@
|
||||||
import * as http from 'http';
|
import * as http from 'http';
|
||||||
|
import { Product } from './interfaces/ISettings';
|
||||||
|
|
||||||
export const getFileContents: (product?: string) => Promise<Buffer> = (product: string = 'assets_swtor_de_de') => new Promise((resolve, reject) => {
|
export default function getFileContents(product: string = 'assets_swtor_de_de', from: number, to: number): Promise<Buffer> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
//Generate URL
|
//Generate URL
|
||||||
const url = `http://cdn-patch.swtor.com/patch/${product}/${product}_-1to0.solidpkg`;
|
const path = `/patch/${product}/${product}_${from}to${to}.solidpkg`;
|
||||||
const path = `/patch/${product}/${product}_-1to0.solidpkg`;
|
|
||||||
const fileName = url.substr(url.lastIndexOf('/') + 1);
|
|
||||||
|
|
||||||
const request = http.request({
|
const request = http.request({
|
||||||
family: 4,
|
family: 4,
|
||||||
|
@ -35,6 +35,5 @@ export const getFileContents: (product?: string) => Promise<Buffer> = (product:
|
||||||
reject(e);
|
reject(e);
|
||||||
});
|
});
|
||||||
request.end();
|
request.end();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
getFileContents();
|
|
||||||
|
|
6
src/installPatch.ts
Normal file
6
src/installPatch.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import getFileContents from './getFileContents';
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const buffer = await getFileContents('assets_swtor_de_de', -1, 0);
|
||||||
|
console.log(buffer.length, buffer);
|
||||||
|
})();
|
11
src/interfaces/ISettings.ts
Normal file
11
src/interfaces/ISettings.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
type Product = 'assets_swtor_de_de' | 'assets_swtor_en_us' | 'assets_swtor_fr_fr' | 'assets_swtor_main' | 'assets_swtor_test_de_de' | 'assets_swtor_test_en_us' | 'assets_swtor_test_fr_fr' | 'assets_swtor_test_main' | 'eualas' | 'movies_de_de' | 'movies_en_us' | 'movies_fr_fr' | 'patcher2014' | 'patcher2017' | 'retailclient_betatest' | 'retailclient_cstraining' | 'retailclient_liveeptest' | 'retailclient_publictest' | 'retailclient_squadron157' | 'retailclient_swtor';
|
||||||
|
|
||||||
|
interface ISettings {
|
||||||
|
[key: string]: any;
|
||||||
|
product?: Product;
|
||||||
|
release?: number; //TODO: allow 'current', but how will we know what current version is?
|
||||||
|
from?: number;
|
||||||
|
outputType?: 'info' | 'file'; //whether to just show JSON information, or actually write files into a directory
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ISettings, Product };
|
Loading…
Reference in a new issue