From 70b377633a99d0e72165cd75b6e68e0997c266dd Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Sun, 20 Oct 2024 16:40:04 -0700 Subject: [PATCH] Validate optimizer tiers --- api/routes/update.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/api/routes/update.ts b/api/routes/update.ts index 31638f4..471259f 100644 --- a/api/routes/update.ts +++ b/api/routes/update.ts @@ -548,6 +548,27 @@ export function validateLoadout(metricPrefix: string, loadout: Loadout, appId: s message: 'Item ID is invalid', }; } + for (const constraint of loadout.parameters?.statConstraints ?? []) { + for (const tier of [constraint.minTier, constraint.maxTier]) { + if (tier === undefined) { + continue; + } + if (!Number.isInteger(tier)) { + metrics.increment(`${metricPrefix}.validation.tierValueNotInteger.count`); + return { + status: 'InvalidArgument', + message: 'Loadout Optimizer stat tiers must be integers, not ${tier}', + }; + } + if (tier < 0 || tier > 10) { + metrics.increment(`${metricPrefix}.validation.tierValueOutOfRange.count`); + return { + status: 'InvalidArgument', + message: 'Loadout Optimizer stat tiers must be between 0 and 10', + }; + } + } + } return undefined; }