From 7a81a67132d3b4b07430adf1e1d933bc902fab54 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Thu, 21 Jun 2018 21:40:27 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Extract=20product=20name?= =?UTF-8?q?=20verification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.ts | 5 ++--- src/getFileContents.ts | 8 +++++++- src/verifyProductName.ts | 7 +++++++ 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 src/verifyProductName.ts 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); +}