mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-07 22:38:02 +03:00
refactor ParserFunctionReturns(A)Sync to just ParserFunctionReturns
This commit is contained in:
@@ -58,7 +58,7 @@ export default async function ScoreImportMain<D, C>(
|
||||
|
||||
logger.debug(`Parsing took ${parseTime} miliseconds.`);
|
||||
|
||||
// We have to cast here due to typescript generic confusions. This is guaranteed to be correct.
|
||||
// We have to cast here due to typescript generic confusions. This is guaranteed` to be correct.
|
||||
const ConverterFunction = Converters[importType] as unknown as ConverterFunction<D, C>;
|
||||
|
||||
// --- 2. Importing ---
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
import {
|
||||
AnyChartDocument,
|
||||
config,
|
||||
integer,
|
||||
ScoreDocument,
|
||||
AnySongDocument,
|
||||
} from "tachi-common";
|
||||
import { AnyChartDocument, config, integer, ScoreDocument, AnySongDocument } from "tachi-common";
|
||||
import { KtLogger } from "../../../logger/logger";
|
||||
import { CreateCalculatedData } from "../calculated-data/calculated-data";
|
||||
import { CalculateESDForGame } from "../common/score-utils";
|
||||
|
||||
@@ -203,6 +203,10 @@ export async function LoadScoresIntoSessions(
|
||||
const startOfGroup = groupScores[0].timeAchieved!;
|
||||
const endOfGroup = groupScores[groupScores.length - 1].timeAchieved!;
|
||||
|
||||
// A bug exists here where if a session is created
|
||||
// backwards in time, this will grab your PBs
|
||||
// from the future.
|
||||
// @todo #179
|
||||
const pbs = await db["score-pbs"].find({
|
||||
chartID: { $in: groupScores.map((e) => e.chartID) },
|
||||
userID,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { KtLogger } from "../../../../logger/logger";
|
||||
import nodeFetch from "../../../../../utils/fetch";
|
||||
import { TraverseKaiAPI } from "../../common/api-kai/traverse-api";
|
||||
import { ParserFunctionReturnsAsync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
import { EmptyObject } from "../../../../../utils/types";
|
||||
import { ARC_API_URL, ARC_AUTH_TOKEN } from "../../../../setup/config";
|
||||
|
||||
@@ -9,7 +9,7 @@ export function ParseArcDDR(
|
||||
arcProfileID: string,
|
||||
logger: KtLogger,
|
||||
fetch = nodeFetch
|
||||
): ParserFunctionReturnsAsync<unknown, EmptyObject> {
|
||||
): ParserFunctionReturns<unknown, EmptyObject> {
|
||||
return {
|
||||
iterable: TraverseKaiAPI(
|
||||
ARC_API_URL,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { KtLogger } from "../../../../logger/logger";
|
||||
import nodeFetch from "../../../../../utils/fetch";
|
||||
import { TraverseKaiAPI } from "../../common/api-kai/traverse-api";
|
||||
import { ParserFunctionReturnsAsync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
import { EmptyObject } from "../../../../../utils/types";
|
||||
import { ARC_API_URL, ARC_AUTH_TOKEN } from "../../../../setup/config";
|
||||
import { CreateArcIIDXClassHandler } from "./class-handler";
|
||||
@@ -10,7 +10,7 @@ export async function ParseArcIIDX(
|
||||
arcProfileID: string,
|
||||
logger: KtLogger,
|
||||
fetch = nodeFetch
|
||||
): Promise<ParserFunctionReturnsAsync<unknown, EmptyObject>> {
|
||||
): Promise<ParserFunctionReturns<unknown, EmptyObject>> {
|
||||
return {
|
||||
iterable: TraverseKaiAPI(
|
||||
ARC_API_URL,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { KtLogger } from "../../../../logger/logger";
|
||||
import nodeFetch from "../../../../../utils/fetch";
|
||||
import { TraverseKaiAPI } from "../../common/api-kai/traverse-api";
|
||||
import { ParserFunctionReturnsAsync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
import { EmptyObject } from "../../../../../utils/types";
|
||||
import { ARC_API_URL, ARC_AUTH_TOKEN } from "../../../../setup/config";
|
||||
|
||||
@@ -9,7 +9,7 @@ export function ParseArcSDVX(
|
||||
arcProfileID: string,
|
||||
logger: KtLogger,
|
||||
fetch = nodeFetch
|
||||
): ParserFunctionReturnsAsync<unknown, EmptyObject> {
|
||||
): ParserFunctionReturns<unknown, EmptyObject> {
|
||||
return {
|
||||
iterable: TraverseKaiAPI(
|
||||
ARC_API_URL,
|
||||
|
||||
@@ -3,7 +3,7 @@ import nodeFetch from "../../../../../../utils/fetch";
|
||||
import { KaiAuthDocument } from "tachi-common";
|
||||
import { KaiContext } from "../types";
|
||||
import { TraverseKaiAPI } from "../traverse-api";
|
||||
import { ParserFunctionReturnsAsync } from "../../types";
|
||||
import { ParserFunctionReturns } from "../../types";
|
||||
import { FLO_API_URL, EAG_API_URL } from "../../../../../setup/config";
|
||||
|
||||
export function ParseKaiIIDX(
|
||||
@@ -11,7 +11,7 @@ export function ParseKaiIIDX(
|
||||
authDoc: KaiAuthDocument,
|
||||
logger: KtLogger,
|
||||
fetch = nodeFetch
|
||||
): ParserFunctionReturnsAsync<unknown, KaiContext> {
|
||||
): ParserFunctionReturns<unknown, KaiContext> {
|
||||
const baseUrl = service === "FLO" ? FLO_API_URL : EAG_API_URL;
|
||||
|
||||
return {
|
||||
|
||||
@@ -3,7 +3,7 @@ import nodeFetch from "../../../../../../utils/fetch";
|
||||
import { KaiAuthDocument } from "tachi-common";
|
||||
import { KaiContext } from "../types";
|
||||
import { TraverseKaiAPI } from "../traverse-api";
|
||||
import { ParserFunctionReturnsAsync } from "../../types";
|
||||
import { ParserFunctionReturns } from "../../types";
|
||||
import { EAG_API_URL, FLO_API_URL } from "../../../../../setup/config";
|
||||
|
||||
export function ParseKaiSDVX(
|
||||
@@ -11,7 +11,7 @@ export function ParseKaiSDVX(
|
||||
authDoc: KaiAuthDocument,
|
||||
logger: KtLogger,
|
||||
fetch = nodeFetch
|
||||
): ParserFunctionReturnsAsync<unknown, KaiContext> {
|
||||
): ParserFunctionReturns<unknown, KaiContext> {
|
||||
const baseUrl = service === "FLO" ? FLO_API_URL : EAG_API_URL;
|
||||
|
||||
return {
|
||||
|
||||
@@ -4,10 +4,9 @@ import { BatchManual, BatchManualContext, BatchManualScore } from "./types";
|
||||
import p, { PrudenceSchema, ValidSchemaValue } from "prudence";
|
||||
import { lamps, validHitData, validPlaytypes } from "tachi-common/js/config";
|
||||
import { Game, ImportTypes } from "tachi-common";
|
||||
import { ConverterBatchManual } from "./converter";
|
||||
import deepmerge from "deepmerge";
|
||||
import { FormatPrError } from "../../../../../utils/prudence";
|
||||
import { ParserFunctionReturnsSync } from "../types";
|
||||
import { ParserFunctionReturns } from "../types";
|
||||
import { CONF_INFO } from "../../../../setup/config";
|
||||
|
||||
const optNull = (v: ValidSchemaValue) => p.optional(p.nullable(v));
|
||||
@@ -117,7 +116,7 @@ export function ParseBatchManualFromObject(
|
||||
object: unknown,
|
||||
importType: ImportTypes,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<BatchManualScore, BatchManualContext> {
|
||||
): ParserFunctionReturns<BatchManualScore, BatchManualContext> {
|
||||
// now to perform some basic validation so we can return
|
||||
// the iterable
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Difficulties } from "tachi-common";
|
||||
import { KtLogger } from "../../../../logger/logger";
|
||||
import ScoreImportFatalError from "../../../framework/score-importing/score-import-error";
|
||||
import { ParserFunctionReturnsSync } from "../types";
|
||||
import { ParserFunctionReturns } from "../types";
|
||||
import { EamusementScoreData, IIDXEamusementCSVContext, IIDXEamusementCSVData } from "./types";
|
||||
|
||||
enum EAM_VERSION_NAMES {
|
||||
@@ -220,7 +220,7 @@ function GenericParseEamIIDXCSV(
|
||||
body: Record<string, unknown>,
|
||||
service: string,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<IIDXEamusementCSVData, IIDXEamusementCSVContext> {
|
||||
): ParserFunctionReturns<IIDXEamusementCSVData, IIDXEamusementCSVContext> {
|
||||
let playtype: "SP" | "DP";
|
||||
|
||||
if (body.playtype === "SP") {
|
||||
|
||||
@@ -103,19 +103,8 @@ export interface ImportInputParser<D, C> {
|
||||
(logger: KtLogger): ParserFunctionReturns<D, C> | Promise<ParserFunctionReturns<D, C>>;
|
||||
}
|
||||
|
||||
export type ParserFunctionReturns<D, C> =
|
||||
| ParserFunctionReturnsAsync<D, C>
|
||||
| ParserFunctionReturnsSync<D, C>;
|
||||
|
||||
export interface ParserFunctionReturnsAsync<D, C> {
|
||||
iterable: AsyncIterable<D>;
|
||||
context: C;
|
||||
game: Game;
|
||||
classHandler: ClassHandler | null;
|
||||
}
|
||||
|
||||
export interface ParserFunctionReturnsSync<D, C> {
|
||||
iterable: Iterable<D>;
|
||||
export interface ParserFunctionReturns<D, C> {
|
||||
iterable: Iterable<D> | AsyncIterable<D>;
|
||||
context: C;
|
||||
game: Game;
|
||||
classHandler: ClassHandler | null;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { KtLogger } from "../../../../logger/logger";
|
||||
import ScoreImportFatalError from "../../../framework/score-importing/score-import-error";
|
||||
import { ParseBatchManualFromObject } from "../../common/batch-manual/parser";
|
||||
import { BatchManualContext, BatchManualScore } from "../../common/batch-manual/types";
|
||||
import { ParserFunctionReturnsSync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
|
||||
/**
|
||||
* Parses a buffer of BATCH-MANUAL data.
|
||||
@@ -13,7 +13,7 @@ function ParseBatchManual(
|
||||
fileData: Express.Multer.File,
|
||||
body: Record<string, unknown>,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<BatchManualScore, BatchManualContext> {
|
||||
): ParserFunctionReturns<BatchManualScore, BatchManualContext> {
|
||||
let jsonData: unknown;
|
||||
|
||||
try {
|
||||
|
||||
@@ -4,13 +4,13 @@ import {
|
||||
IIDXEamusementCSVContext,
|
||||
IIDXEamusementCSVData,
|
||||
} from "../../common/eamusement-iidx-csv/types";
|
||||
import { ParserFunctionReturnsSync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
|
||||
function ParseEamusementIIDXCSV(
|
||||
fileData: Express.Multer.File,
|
||||
body: Record<string, unknown>,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<IIDXEamusementCSVData, IIDXEamusementCSVContext> {
|
||||
): ParserFunctionReturns<IIDXEamusementCSVData, IIDXEamusementCSVContext> {
|
||||
return GenericParseEamIIDXCSV(fileData, body, "e-amusement", logger);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { FormatPrError } from "../../../../../utils/prudence";
|
||||
import { EmptyObject } from "../../../../../utils/types";
|
||||
import { KtLogger } from "../../../../logger/logger";
|
||||
import ScoreImportFatalError from "../../../framework/score-importing/score-import-error";
|
||||
import { ParserFunctionReturnsSync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
import { ConvertFileMerIIDX } from "./converter";
|
||||
import { MerScore } from "./types";
|
||||
|
||||
@@ -30,7 +30,7 @@ export function ParseMerIIDX(
|
||||
fileData: Express.Multer.File,
|
||||
body: Record<string, unknown>,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<MerScore, EmptyObject> {
|
||||
): ParserFunctionReturns<MerScore, EmptyObject> {
|
||||
let jsonData;
|
||||
|
||||
try {
|
||||
|
||||
@@ -4,13 +4,13 @@ import {
|
||||
IIDXEamusementCSVContext,
|
||||
IIDXEamusementCSVData,
|
||||
} from "../../common/eamusement-iidx-csv/types";
|
||||
import { ParserFunctionReturnsSync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
|
||||
function ParsePLIIIDXCSV(
|
||||
fileData: Express.Multer.File,
|
||||
body: Record<string, unknown>,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<IIDXEamusementCSVData, IIDXEamusementCSVContext> {
|
||||
): ParserFunctionReturns<IIDXEamusementCSVData, IIDXEamusementCSVContext> {
|
||||
return GenericParseEamIIDXCSV(fileData, body, "PLI", logger);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import ScoreImportFatalError from "../../../framework/score-importing/score-impo
|
||||
import p, { PrudenceSchema } from "prudence";
|
||||
import { FormatPrError } from "../../../../../utils/prudence";
|
||||
import { S3Score } from "./types";
|
||||
import { ParserFunctionReturnsSync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
import { KtLogger } from "../../../../logger/logger";
|
||||
|
||||
const PR_SolidState: PrudenceSchema = {
|
||||
@@ -54,7 +54,7 @@ export function ParseSolidStateXML(
|
||||
fileData: Express.Multer.File,
|
||||
body: Record<string, unknown>,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<S3Score, EmptyObject> {
|
||||
): ParserFunctionReturns<S3Score, EmptyObject> {
|
||||
let parsedXML;
|
||||
|
||||
try {
|
||||
|
||||
@@ -5,7 +5,7 @@ import ScoreImportFatalError from "../../../framework/score-importing/score-impo
|
||||
import { FormatPrError } from "../../../../../utils/prudence";
|
||||
import { BarbatosScore } from "./types";
|
||||
import { ConverterIRBarbatos } from "./converter";
|
||||
import { ParserFunctionReturnsSync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
|
||||
const PR_Barbatos = {
|
||||
difficulty: p.isIn(1, 2, 3, 4),
|
||||
@@ -28,7 +28,7 @@ const PR_Barbatos = {
|
||||
export function ParseBarbatosSingle(
|
||||
body: Record<string, unknown>,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<BarbatosScore, EmptyObject> {
|
||||
): ParserFunctionReturns<BarbatosScore, EmptyObject> {
|
||||
const err = p(body, PR_Barbatos);
|
||||
|
||||
if (err) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import ScoreImportFatalError from "../../../framework/score-importing/score-impo
|
||||
import { FormatPrError } from "../../../../../utils/prudence";
|
||||
import { BeatorajaChart, BeatorajaContext, BeatorajaScore } from "./types";
|
||||
import { ConverterIRBeatoraja } from "./converter";
|
||||
import { ParserFunctionReturnsSync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
|
||||
const PR_BeatorajaScore = {
|
||||
sha256: "string",
|
||||
@@ -65,7 +65,7 @@ const PR_BeatorajaChart = {
|
||||
export function ParseBeatorajaSingle(
|
||||
body: Record<string, unknown>,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<BeatorajaScore, BeatorajaContext> {
|
||||
): ParserFunctionReturns<BeatorajaScore, BeatorajaContext> {
|
||||
const err = p(
|
||||
body.score,
|
||||
PR_BeatorajaScore,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { KtLogger } from "../../../../logger/logger";
|
||||
import { ParseBatchManualFromObject } from "../../common/batch-manual/parser";
|
||||
import { BatchManualContext, BatchManualScore } from "../../common/batch-manual/types";
|
||||
import { ParserFunctionReturnsSync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
|
||||
/**
|
||||
* Parses an object of BATCH-MANUAL data.
|
||||
@@ -11,7 +11,7 @@ import { ParserFunctionReturnsSync } from "../../common/types";
|
||||
function ParseDirectManual(
|
||||
body: Record<string, unknown>,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<BatchManualScore, BatchManualContext> {
|
||||
): ParserFunctionReturns<BatchManualScore, BatchManualContext> {
|
||||
return ParseBatchManualFromObject(body, "ir/direct-manual", logger);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { FervidexStaticContext, FervidexStaticScore } from "./types";
|
||||
import { FerHeaders, SoftwareIDToVersion } from "../fervidex/parser";
|
||||
import { AssertStrAsPositiveInt } from "../../../framework/common/string-asserts";
|
||||
import { CreateFerStaticClassHandler } from "./class-handler";
|
||||
import { ParserFunctionReturnsSync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
|
||||
const PR_FervidexStatic: PrudenceSchema = {
|
||||
ex_score: p.isPositiveInteger,
|
||||
@@ -19,7 +19,7 @@ export function ParseFervidexStatic(
|
||||
body: Record<string, unknown>,
|
||||
headers: FerHeaders,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<FervidexStaticScore, FervidexStaticContext> {
|
||||
): ParserFunctionReturns<FervidexStaticScore, FervidexStaticContext> {
|
||||
const version = SoftwareIDToVersion(headers.model);
|
||||
|
||||
const staticScores = body?.scores;
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
REV_2DXTRA,
|
||||
REV_OMNIMIX,
|
||||
} from "../../../../constants/ea3id";
|
||||
import { ParserFunctionReturnsSync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
|
||||
const PR_Fervidex: PrudenceSchema = {
|
||||
chart: p.isIn("spb", "spn", "dpn", "sph", "dph", "spa", "dpa", "spl", "dpl"),
|
||||
@@ -100,7 +100,7 @@ export function ParseFervidexSingle(
|
||||
body: Record<string, unknown>,
|
||||
headers: FerHeaders,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<FervidexScore, FervidexContext> {
|
||||
): ParserFunctionReturns<FervidexScore, FervidexContext> {
|
||||
const version = SoftwareIDToVersion(headers.model);
|
||||
|
||||
// more mods may be added in the future, so lets ignore excess keys.
|
||||
|
||||
@@ -5,7 +5,7 @@ import { FormatPrError } from "../../../../../utils/prudence";
|
||||
import { USCClientScore } from "../../../../../server/router/ir/usc/types";
|
||||
import { IRUSCContext } from "./types";
|
||||
import { ConverterIRUSC } from "./converter";
|
||||
import { ParserFunctionReturnsSync } from "../../common/types";
|
||||
import { ParserFunctionReturns } from "../../common/types";
|
||||
import ScoreImportFatalError from "../../../framework/score-importing/score-import-error";
|
||||
|
||||
const PR_USCIRScore: PrudenceSchema = {
|
||||
@@ -27,7 +27,7 @@ export function ParseIRUSC(
|
||||
body: Record<string, unknown>,
|
||||
chart: ChartDocument<"usc:Single">,
|
||||
logger: KtLogger
|
||||
): ParserFunctionReturnsSync<USCClientScore, IRUSCContext> {
|
||||
): ParserFunctionReturns<USCClientScore, IRUSCContext> {
|
||||
const err = p(
|
||||
body.score,
|
||||
PR_USCIRScore,
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
GetUserCaseInsensitive,
|
||||
PRIVATEINFO_GetUserCaseInsensitive,
|
||||
} from "../../../../../utils/user";
|
||||
|
||||
import db from "../../../../../external/mongo/db";
|
||||
import CreateLogCtx from "../../../../../lib/logger/logger";
|
||||
import prValidate from "../../../../middleware/prudence-validate";
|
||||
@@ -152,7 +151,7 @@ router.post(
|
||||
});
|
||||
}
|
||||
|
||||
logger.verbose("Captcha validated!");
|
||||
logger.debug("Captcha validated.");
|
||||
} else {
|
||||
logger.info("Skipped captcha check because not in production.");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export function FindSongOnTitle(
|
||||
game: Game,
|
||||
title: string
|
||||
): Promise<FindOneResult<AnySongDocument>> {
|
||||
// @PERF: Performance should be tested here by having a utility field for all-titles.
|
||||
// @optimisable: Performance should be tested here by having a utility field for all-titles.
|
||||
return db.songs[game].findOne({
|
||||
$or: [
|
||||
{
|
||||
@@ -38,7 +38,7 @@ export function FindSongOnTitleInsensitive(
|
||||
game: Game,
|
||||
title: string
|
||||
): Promise<FindOneResult<AnySongDocument>> {
|
||||
// @PERF: Performance should be tested here by having a utility field for all-titles.
|
||||
// @optimisable: Performance should be tested here by having a utility field for all-titles.
|
||||
|
||||
const regex = new RegExp(`^${EscapeStringRegexp(title)}$`, "iu");
|
||||
return db.songs[game].findOne({
|
||||
|
||||
Reference in New Issue
Block a user