mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-06 22:07:58 +03:00
Make fervidex/profile/submit respond instantly no matter what.
This commit is contained in:
@@ -4,6 +4,7 @@ import { InsertFakeTokenWithAllPerms } from "test-utils/fake-auth";
|
||||
import mockApi from "test-utils/mock-api";
|
||||
import ResetDBState from "test-utils/resets";
|
||||
import { GetKTDataJSON } from "test-utils/test-data";
|
||||
import { Sleep } from "utils/misc";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function TestHeaders(url: string, data: any) {
|
||||
@@ -359,23 +360,12 @@ t.test("POST /ir/fervidex/profile/submit", (t) => {
|
||||
.set("X-Software-Model", "P2D:J:B:A:2020092900")
|
||||
.send(ferStaticBody);
|
||||
|
||||
t.equal(res.body.success, true, "Should be successful");
|
||||
t.equal(res.statusCode, 202, "Should be deferred for later processing.");
|
||||
|
||||
t.equal(res.body.body.errors.length, 0, "Should have 0 failed scores.");
|
||||
|
||||
t.strictSame(
|
||||
res.body.body.classDeltas,
|
||||
[
|
||||
{
|
||||
game: "iidx",
|
||||
set: "dan",
|
||||
playtype: "SP",
|
||||
old: null,
|
||||
new: 15,
|
||||
},
|
||||
],
|
||||
"Should return updated dan deltas."
|
||||
);
|
||||
// Not sure how long this import should take, but sleeping for 5 seconds
|
||||
// seems like a very conservative estimate.
|
||||
// Then we can check whether the database has properly updated.
|
||||
await Sleep(5_000);
|
||||
|
||||
const scores = await db.scores.count({
|
||||
service: "Fervidex Static",
|
||||
@@ -408,23 +398,10 @@ t.test("POST /ir/fervidex/profile/submit", (t) => {
|
||||
.set("X-Software-Model", "LDJ:J:B:A:2020092900")
|
||||
.send(ferStaticBody);
|
||||
|
||||
t.equal(res.body.success, true, "Should be successful");
|
||||
t.equal(res.statusCode, 202, "Should be deferred for later processing.");
|
||||
|
||||
t.equal(res.body.body.errors.length, 0, "Should have 0 failed scores.");
|
||||
|
||||
t.strictSame(
|
||||
res.body.body.classDeltas,
|
||||
[
|
||||
{
|
||||
game: "iidx",
|
||||
set: "dan",
|
||||
playtype: "SP",
|
||||
old: null,
|
||||
new: 15,
|
||||
},
|
||||
],
|
||||
"Should return updated dan deltas."
|
||||
);
|
||||
// See above.
|
||||
await Sleep(5_000);
|
||||
|
||||
const scores = await db.scores.count({
|
||||
service: "Fervidex Static",
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
import { SYMBOL_TachiAPIAuth } from "lib/constants/tachi";
|
||||
import CreateLogCtx from "lib/logger/logger";
|
||||
import { ExpressWrappedScoreImportMain } from "lib/score-import/framework/express-wrapper";
|
||||
import { MakeScoreImport } from "lib/score-import/framework/score-import";
|
||||
import { RequirePermissions } from "server/middleware/auth";
|
||||
import { integer, Playtypes } from "tachi-common";
|
||||
import { UpdateClassIfGreater } from "utils/class";
|
||||
@@ -196,28 +197,23 @@ router.use(
|
||||
*
|
||||
* @name POST /ir/fervidex/profile/submit
|
||||
*/
|
||||
router.post("/profile/submit", RequireInf2ModelHeaderOrForceStatic, async (req, res) => {
|
||||
router.post("/profile/submit", RequireInf2ModelHeaderOrForceStatic, (req, res) => {
|
||||
const headers = {
|
||||
// guaranteed to exist because of RequireInf2ModelHeader
|
||||
model: req.header("X-Software-Model")!,
|
||||
};
|
||||
|
||||
const responseData = await ExpressWrappedScoreImportMain(
|
||||
req[SYMBOL_TachiAPIAuth].userID!,
|
||||
false,
|
||||
"ir/fervidex-static",
|
||||
[req.body, headers]
|
||||
);
|
||||
// Perform a fast return here to not allow fervidex to resend requests.
|
||||
res.status(202).json({
|
||||
success: true,
|
||||
description: `Your import has been loaded for further processing.`,
|
||||
body: {},
|
||||
});
|
||||
|
||||
if (!responseData.body.success) {
|
||||
// in-air rewrite description to error.
|
||||
// @ts-expect-error Hack!
|
||||
responseData.body.error = responseData.body.description;
|
||||
// @ts-expect-error Hack!
|
||||
delete responseData.body.description;
|
||||
}
|
||||
|
||||
return res.status(responseData.statusCode).json(responseData.body);
|
||||
ExpressWrappedScoreImportMain(req[SYMBOL_TachiAPIAuth].userID!, false, "ir/fervidex-static", [
|
||||
req.body,
|
||||
headers,
|
||||
]);
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user