diff --git a/src/config.ts b/src/config.ts index e0ae782..40cff0a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,6 +1,5 @@ import { ISettings, Product } from './interfaces/ISettings'; - -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']; +import verifyProductName from './verifyProductName'; const settings: ISettings = {}; @@ -10,7 +9,7 @@ export const set = (key: string, value: any) => { case 'product': //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 (!allowedProducts.includes(value as Product)) { throw new Error(`"${value}" is not an allowed product.`); } + if (!verifyProductName(value)) { throw new Error(`"${value}" is not an allowed product.`); } settings.product = value as Product; break; case 'release': diff --git a/src/getFileContents.ts b/src/getFileContents.ts index 5b10f56..f650113 100644 --- a/src/getFileContents.ts +++ b/src/getFileContents.ts @@ -1,8 +1,14 @@ import * as http from 'http'; import { Product } from './interfaces/ISettings'; +import verifyProductName from './verifyProductName'; -export default function getFileContents(product: string = 'assets_swtor_de_de', from: number, to: number): Promise { +export default function getFileContents(product: Product, from: number, to: number): Promise { return new Promise((resolve, reject) => { + if (!verifyProductName(product)) { + return reject(`"${product}" is not a valid product.`); + } + //TODO: also verify from and to + //Generate URL const path = `/patch/${product}/${product}_${from}to${to}.solidpkg`; diff --git a/src/verifyProductName.ts b/src/verifyProductName.ts new file mode 100644 index 0000000..969478f --- /dev/null +++ b/src/verifyProductName.ts @@ -0,0 +1,7 @@ +import { Product } from './interfaces/ISettings'; + +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']; + +export default function verifyProductName(name: string) { + return allowedProducts.includes(name as Product); +}