mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-07 14:28:09 +03:00
add ea3softid parsing
This commit is contained in:
@@ -101,6 +101,26 @@ t.test("POST /api/ir/fervidex/score/submit", async (t) => {
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should import a valid score with 2dx-gsm", async (t) => {
|
||||
let res = await mockApi
|
||||
.post("/api/ir/fervidex/score/submit")
|
||||
.set("Cookie", cookie)
|
||||
.set("X-Software-Model", "LDJ:J:B:A:2020092900")
|
||||
.send(GetKTDataJSON("./fervidex/2dxgsm.json"));
|
||||
|
||||
t.equal(res.body.success, true, "Should be successful");
|
||||
|
||||
t.equal(res.body.body.errors.length, 0, "Should have 0 failed scores.");
|
||||
|
||||
let scores = await db.scores.count({
|
||||
service: "Fervidex",
|
||||
});
|
||||
|
||||
t.equal(scores, 1, "Should import 1 score.");
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should reject an invalid body", async (t) => {
|
||||
let res = await mockApi
|
||||
.post("/api/ir/fervidex/score/submit")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Router, RequestHandler } from "express";
|
||||
import { GetUserWithIDGuaranteed } from "../../../common/user";
|
||||
import { ParseEA3SoftID } from "../../../common/util";
|
||||
import { IIDX_AC_MODEL, INF2_MODEL, REV_2DXBMS } from "../../../constants/ea3id";
|
||||
import { RequireLoggedIn } from "../../../middleware/require-logged-in";
|
||||
import { ExpressWrappedScoreImportMain } from "../../../score-import/framework/express-wrapper";
|
||||
import { ParseFervidexStatic } from "../../../score-import/import-types/ir/fervidex-static/parser";
|
||||
@@ -10,10 +12,26 @@ const router: Router = Router({ mergeParams: true });
|
||||
const RequireInf2ModelHeader: RequestHandler = async (req, res, next) => {
|
||||
let swModel = req.header("X-Software-Model");
|
||||
|
||||
if (!swModel || !swModel.startsWith("P2D:J:B:A")) {
|
||||
return res.status(400).send({
|
||||
if (!swModel) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
description: "This endpoint is only available for INF2 clients.",
|
||||
description: `Invalid X-Software-Model.`,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
let softID = ParseEA3SoftID(swModel);
|
||||
|
||||
if (softID.model !== INF2_MODEL) {
|
||||
return res.status(400).send({
|
||||
success: false,
|
||||
description: "This endpoint is only available for INF2 clients.",
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
description: `Invalid X-Software-Model.`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,8 +41,27 @@ const RequireInf2ModelHeader: RequestHandler = async (req, res, next) => {
|
||||
const ValidateModelHeader: RequestHandler = async (req, res, next) => {
|
||||
let swModel = req.header("X-Software-Model");
|
||||
|
||||
if (!swModel || swModel.startsWith("LDJ:J:B:X") || swModel.startsWith("LDJ:J:B:Z")) {
|
||||
return res.status(400).send({ success: false, description: "Invalid X-Software-Model." });
|
||||
if (!swModel) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
description: `Invalid X-Software-Model.`,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
let softID = ParseEA3SoftID(swModel);
|
||||
|
||||
if (softID.rev !== REV_2DXBMS) {
|
||||
return res.status(400).send({
|
||||
success: false,
|
||||
description: "2DX_BMS is not supported.",
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
description: `Invalid X-Software-Model.`,
|
||||
});
|
||||
}
|
||||
|
||||
return next();
|
||||
|
||||
Reference in New Issue
Block a user