♻️ Extract product name verification
This commit is contained in:
parent
8424ae8978
commit
7a81a67132
3 changed files with 16 additions and 4 deletions
|
@ -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':
|
||||
|
|
|
@ -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<Buffer> {
|
||||
export default function getFileContents(product: Product, from: number, to: number): Promise<Buffer> {
|
||||
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`;
|
||||
|
||||
|
|
7
src/verifyProductName.ts
Normal file
7
src/verifyProductName.ts
Normal file
|
@ -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);
|
||||
}
|
Loading…
Reference in a new issue