From e921d2bb7b265123c2139391d4e1e455bd15afb1 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Wed, 2 Nov 2022 03:33:15 +0000 Subject: [PATCH] feat: fervidex ch-omni enable --- .../score-import/import-types/ir/fervidex/parser.ts | 3 ++- server/src/server/router/ir/fervidex/router.ts | 8 ++++++-- server/src/utils/ea3id.ts | 12 +++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/server/src/lib/score-import/import-types/ir/fervidex/parser.ts b/server/src/lib/score-import/import-types/ir/fervidex/parser.ts index 5523c84cb..f713702aa 100644 --- a/server/src/lib/score-import/import-types/ir/fervidex/parser.ts +++ b/server/src/lib/score-import/import-types/ir/fervidex/parser.ts @@ -101,11 +101,12 @@ export function SoftwareIDToVersion(model: string, logger: KtLogger) { } else if (data.ext === EXT_CASTHOUR) { if (data.rev === REV_NORMAL) { return "29"; + } else if (data.rev === REV_2DXTRA) { + return "29-omni"; } } } - logger.warn(`Unsupported Software Model ${model}.`); throw new ScoreImportFatalError(400, `Unsupported Software Model ${model}.`); } catch (err) { logger.warn(`Unsupported Software Model ${model}.`, { err }); diff --git a/server/src/server/router/ir/fervidex/router.ts b/server/src/server/router/ir/fervidex/router.ts index 76b6b702a..af161fdfb 100644 --- a/server/src/server/router/ir/fervidex/router.ts +++ b/server/src/server/router/ir/fervidex/router.ts @@ -10,6 +10,7 @@ import { import { SYMBOL_TACHI_API_AUTH } from "lib/constants/tachi"; import CreateLogCtx from "lib/logger/logger"; import { ExpressWrappedScoreImportMain } from "lib/score-import/framework/express-wrapper"; +import { SoftwareIDToVersion } from "lib/score-import/import-types/ir/fervidex/parser"; import p from "prudence"; import { RequirePermissions } from "server/middleware/auth"; import { PrudenceErrorFormatter } from "server/middleware/prudence-validate"; @@ -104,9 +105,12 @@ const ValidateModelHeader: RequestHandler = (req, res, next) => { return; } - if (softID.ext === undefined || !supportedExts.includes(softID.ext)) { + try { + SoftwareIDToVersion(swModel, logger); + } catch (err) { logger.info( - `Rejected invalid Software Model ${softID.ext} from user ${req[SYMBOL_TACHI_API_AUTH].userID}.` + `Rejected invalid Software Model ${softID.ext} from user ${req[SYMBOL_TACHI_API_AUTH].userID}.`, + { err } ); return res.status(400).json({ success: false, diff --git a/server/src/utils/ea3id.ts b/server/src/utils/ea3id.ts index c1a0019ad..4dfefdcdb 100644 --- a/server/src/utils/ea3id.ts +++ b/server/src/utils/ea3id.ts @@ -5,18 +5,20 @@ export function ParseEA3SoftID(ver: string) { throw new Error(`Invalid Version Code. Had ${a.length} components.`); } + const arr = a as [string, string, string, string, string]; + if (!/^[A-Z0-9]{3}:[A-Z]:[A-Z]:[A-Z]:[0-9]{10}$/u.exec(ver)) { throw new Error(`Invalid Version Code.`); } return { - model: a[0], + model: arr[0], // region - dest: a[1], + dest: arr[1], - spec: a[2], - rev: a[3], - ext: a[4], + spec: arr[2], + rev: arr[3], + ext: arr[4], }; }