🔒 Verify input to releasePaths

This commit is contained in:
C-3PO 2018-06-22 18:21:27 +02:00
parent 620cb8bb1d
commit 053714bf10
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -1,5 +1,8 @@
import { Product } from '../interfaces/ISettings';
import verifyProductName from '../ssn/verifyProductName';
/** For the given release in the given product, returns from which releases we can patch to this release. */
function getFroms({ product, to: releaseTo}: {product: string, to: number}) {
function getFroms({ product, to: releaseTo}: {product: Product, to: number}) {
//The launcher (patcher, patcher2014, patcher2017) is always installing from -1, never from a previous version
if (product.startsWith('patcher')) {
return [-1];
@ -47,8 +50,16 @@ function getFroms({ product, to: releaseTo}: {product: string, to: number}) {
* Does not actually look at the manifest.xml file but theorizes on possible patches based on the usually created patches, allowing
* us to find release pathes for products that have not been released yet.
*/
export default function findReleasePath({ product, from, to}: {product: string, from: number, to: number}): Array<[number, number]> {
export default function findReleasePath({ product, from, to}: {product: Product, from: number, to: number}): Array<[number, number]> {
//Verify function arguments
if (!verifyProductName(product)) {
throw new Error(`"${product}" is not a valid product.`);
}
//We assume that "from < to" is true for all patches
if (from > to) {
throw new Error('Cannot patch backwards; to must be greater than from.');
}
const froms = getFroms({ product, to });