chart_pb support

This commit is contained in:
zkldi
2022-03-22 01:44:07 +00:00
parent 0670462d3a
commit 52e8ecf564
9 changed files with 288 additions and 70 deletions
+33
View File
@@ -6,8 +6,12 @@ import {
Playtype,
PublicUserDocument,
integer,
ChartDocument,
SongDocument,
PBScoreDocument,
} from "tachi-common";
import { LoggerLayers } from "../data/data";
import db from "../database/mongo";
import { RequestTypes, TachiServerV1Get, TachiServerV1Request } from "./fetchTachi";
import { CreateLayeredLogger } from "./logger";
import { Sleep } from "./misc";
@@ -51,6 +55,35 @@ export async function GetGoalWithID(goalID: string, game: Game, playtype: Playty
return res.body;
}
export async function GetChartInfoForUser(
userID: integer | string,
chartID: string,
game: Game,
playtype: Playtype
) {
const res = await TachiServerV1Get<{ song: SongDocument; chart: ChartDocument }>(
`/games/${game}/${playtype}/charts/${chartID}`,
null
);
if (!res.success) {
throw new Error(`Failed to fetch song/chart with chartID ${chartID}.`);
}
const pbRes = await TachiServerV1Get<{ chart: ChartDocument; pb: PBScoreDocument }>(
`/users/${userID}/games/${game}/${playtype}/pbs/${chartID}`,
null
);
const pb = pbRes.success ? pbRes.body.pb : null;
if (pb === null && pbRes.statusCode !== 404) {
throw new Error(`Failed to fetch score info for userID ${userID} on chart ${chartID}.`);
}
return { song: res.body.song, chart: res.body.chart, pb };
}
export async function PerformScoreImport(
url: string,
authToken: string,