From c52cf36adf03e4892b5c80cb73639f9e70cb01c3 Mon Sep 17 00:00:00 2001 From: zkldi Date: Tue, 25 May 2021 18:18:40 +0100 Subject: [PATCH] move ea3id --- .../import-types/ir/fervidex/parser.ts | 2 +- .../src/server/router/ir/fervidex/router.ts | 2 +- server/src/server/server.ts | 2 +- server/src/utils/ea3id.ts | 19 ++++++++++++++++++ server/src/utils/util.ts | 20 ------------------- 5 files changed, 22 insertions(+), 23 deletions(-) create mode 100644 server/src/utils/ea3id.ts diff --git a/server/src/score-import/import-types/ir/fervidex/parser.ts b/server/src/score-import/import-types/ir/fervidex/parser.ts index cb31032cf..ae0a21235 100644 --- a/server/src/score-import/import-types/ir/fervidex/parser.ts +++ b/server/src/score-import/import-types/ir/fervidex/parser.ts @@ -4,7 +4,7 @@ import ScoreImportFatalError from "../../../framework/score-importing/score-impo import { FormatPrError, optNull } from "../../../../utils/prudence"; import { FervidexContext, FervidexScore } from "./types"; import { ConverterIRFervidex } from "./converter"; -import { ParseEA3SoftID } from "../../../../utils/util"; +import { ParseEA3SoftID } from "../../../../utils/ea3id"; import { EXT_HEROIC_VERSE, MODEL_IIDX, diff --git a/server/src/server/router/ir/fervidex/router.ts b/server/src/server/router/ir/fervidex/router.ts index 8818d5a5e..c3188bdf6 100644 --- a/server/src/server/router/ir/fervidex/router.ts +++ b/server/src/server/router/ir/fervidex/router.ts @@ -1,7 +1,7 @@ import { Router, RequestHandler } from "express"; import { UpdateClassIfGreater } from "../../../../utils/class"; import { GetUserWithIDGuaranteed } from "../../../../utils/user"; -import { ParseEA3SoftID } from "../../../../utils/util"; +import { ParseEA3SoftID } from "../../../../utils/ea3id"; import { EXT_HEROIC_VERSE, MODEL_INFINITAS_2, REV_2DXBMS } from "../../../../constants/ea3id"; import { RequireLoggedIn } from "../../../middleware/require-logged-in"; import { ExpressWrappedScoreImportMain } from "../../../../score-import/framework/express-wrapper"; diff --git a/server/src/server/server.ts b/server/src/server/server.ts index e43d48fe4..e07ce01ec 100644 --- a/server/src/server/server.ts +++ b/server/src/server/server.ts @@ -52,7 +52,7 @@ app.use(express.json({ limit: "1mb" })); import mainRouter from "./router/router"; -app.use("/", apiRouter); +app.use("/", mainRouter); /** * If any user gets to this point, we send them index.html and let react router do the routing (and 404ing) diff --git a/server/src/utils/ea3id.ts b/server/src/utils/ea3id.ts new file mode 100644 index 000000000..54476f48a --- /dev/null +++ b/server/src/utils/ea3id.ts @@ -0,0 +1,19 @@ +export function ParseEA3SoftID(ver: string) { + const a = ver.split(":"); + + if (a.length !== 5) { + throw new Error(`Invalid Version Code. Had ${a.length} components.`); + } + + if (!ver.match(/^[A-Z0-9]{3}:[A-Z]:[A-Z]:[A-Z]:[0-9]{10}$/u)) { + throw new Error(`Invalid Version Code.`); + } + + return { + model: a[0], + dest: a[1], // region + spec: a[2], + rev: a[3], + ext: a[4], + }; +} diff --git a/server/src/utils/util.ts b/server/src/utils/util.ts index 2c516fe07..27c030b53 100644 --- a/server/src/utils/util.ts +++ b/server/src/utils/util.ts @@ -15,26 +15,6 @@ export function EscapeStringRegexp(string: string) { return string.replace(/[|\\{}()[\]^$+*?.]/gu, "\\$&").replace(/-/gu, "\\x2d"); } -export function ParseEA3SoftID(ver: string) { - const a = ver.split(":"); - - if (a.length !== 5) { - throw new Error(`Invalid Version Code. Had ${a.length} components.`); - } - - if (!ver.match(/^[A-Z0-9]{3}:[A-Z]:[A-Z]:[A-Z]:[0-9]{10}$/u)) { - throw new Error(`Invalid Version Code.`); - } - - return { - model: a[0], - dest: a[1], // region - spec: a[2], - rev: a[3], - ext: a[4], - }; -} - /** * Takes a process.hrtime.bigint(), and returns the miliseconds elapsed since it. * This function will not work if more than 100(ish) days have passed since the first reference.