From cfd646c8e188f70ee93f2fa5662d1c766333d01e Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Thu, 18 Aug 2022 17:41:57 +0100 Subject: [PATCH] fix: beatoraja class-submit was broken --- .../server/router/ir/beatoraja/router.test.ts | 4 +-- .../src/server/router/ir/beatoraja/router.ts | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/server/src/server/router/ir/beatoraja/router.test.ts b/server/src/server/router/ir/beatoraja/router.test.ts index eb40e12a2..37c06e1b8 100644 --- a/server/src/server/router/ir/beatoraja/router.test.ts +++ b/server/src/server/router/ir/beatoraja/router.test.ts @@ -392,7 +392,7 @@ const courseScore = { sha256: "", lntype: 0, player: "unknown", - clear: "Clear", + clear: "Normal", date: 0, epg: 1334, lpg: 788, @@ -461,7 +461,7 @@ t.test("POST /ir/beatoraja/submit-course", (t) => { t.equal(res.status, 200); t.equal(res.body.success, true); - t.equal(res.body.description, "Class not updated."); + t.equal(res.body.description, "Class not updated, as you didn't clear this course."); t.end(); }); diff --git a/server/src/server/router/ir/beatoraja/router.ts b/server/src/server/router/ir/beatoraja/router.ts index 334359705..ad7a985b4 100644 --- a/server/src/server/router/ir/beatoraja/router.ts +++ b/server/src/server/router/ir/beatoraja/router.ts @@ -11,7 +11,10 @@ import { RequireNotGuest } from "server/middleware/auth"; import prValidate from "server/middleware/prudence-validate"; import { UpdateClassIfGreater } from "utils/class"; import { IsRecord, NotNullish } from "utils/misc"; -import type { BeatorajaChart } from "lib/score-import/import-types/ir/beatoraja/types"; +import type { + BeatorajaChart, + BeatorajaScore, +} from "lib/score-import/import-types/ir/beatoraja/types"; import type { integer } from "tachi-common"; const logger = CreateLogCtx(__filename); @@ -185,7 +188,22 @@ router.post( constraint: [p.isIn("LN", "MIRROR", "GAUGE_LR2")], }, score: { - clear: p.isIn("Clear", "Failed"), + // For some reason, a course can have any of these lamps. + // Since I'm too lazy to delve into the code to find which of these are actually used + // I'm going to assume any of them can come in, and handle them later. + clear: p.isIn( + "NoPlay", + "Failed", + "AssistEasy", + "LightAssistEasy", + "Easy", + "Normal", + "Hard", + "ExHard", + "FullCombo", + "Perfect", + "Max" + ), lntype: p.isIn(0, 1, 2), }, }, @@ -200,7 +218,7 @@ router.post( constraint: Array<"GAUGE_LR2" | "LN" | "MIRROR">; }; score: { - clear: "Clear" | "Failed"; + clear: BeatorajaScore["clear"]; lntype: 0 | 1 | 2; }; }; @@ -208,10 +226,15 @@ router.post( const charts = body.course.charts; const clear = body.score.clear; - if (clear !== "Clear") { + if ( + clear === "Failed" || + clear === "NoPlay" || + clear === "Easy" || + clear === "LightAssistEasy" + ) { return res.status(200).json({ success: true, - description: "Class not updated.", + description: "Class not updated, as you didn't clear this course.", }); }