diff --git a/server/pnpm-lock.yaml b/server/pnpm-lock.yaml index f52db7f6c..1e5015639 100644 --- a/server/pnpm-lock.yaml +++ b/server/pnpm-lock.yaml @@ -60,7 +60,7 @@ dependencies: express-async-errors: 3.1.1_express@4.17.1 express-session: 1.17.1 fast-json-stable-hash: 1.0.2 - kamaitachi-common: github.com/zkldi/Kamaitachi-common/3ee7ec47e9f5e76a956f09af4fe851d159e31b25 + kamaitachi-common: github.com/zkldi/Kamaitachi-common/ccdc405f9fa6c080d87080106a229f0f403ad8e1 mongodb: 3.6.6 monk: 7.3.4 multer: 1.4.2 @@ -4637,8 +4637,8 @@ packages: '@types/yoga-layout': 1.9.2 dev: true - github.com/zkldi/Kamaitachi-common/3ee7ec47e9f5e76a956f09af4fe851d159e31b25: - resolution: {tarball: https://codeload.github.com/zkldi/Kamaitachi-common/tar.gz/3ee7ec47e9f5e76a956f09af4fe851d159e31b25} + github.com/zkldi/Kamaitachi-common/ccdc405f9fa6c080d87080106a229f0f403ad8e1: + resolution: {tarball: https://codeload.github.com/zkldi/Kamaitachi-common/tar.gz/ccdc405f9fa6c080d87080106a229f0f403ad8e1} name: kamaitachi-common version: 0.1.0 dependencies: diff --git a/server/src/api/import/import.ts b/server/src/api/import/import.ts index f1dab1ab4..56da72182 100644 --- a/server/src/api/import/import.ts +++ b/server/src/api/import/import.ts @@ -117,9 +117,9 @@ export function ResolveFileUploadData( logger: KtLogger ) { switch (importType) { - case "file/csv:eamusement-iidx": + case "file/eamusement-iidx-csv": return ParseEamusementCSV(fileData, body, logger); - case "file/json:batch-manual": + case "file/batch-manual": return ParseBatchManual(fileData, body, logger); default: logger.error( diff --git a/server/src/api/ir/direct-manual/direct-manual.ts b/server/src/api/ir/direct-manual/direct-manual.ts index b8df024c2..177f81d0b 100644 --- a/server/src/api/ir/direct-manual/direct-manual.ts +++ b/server/src/api/ir/direct-manual/direct-manual.ts @@ -29,7 +29,7 @@ router.post("/import", RequireLoggedIn, async (req, res) => { let responseData = await ExpressWrappedScoreImportMain( userDoc, true, - "ir/json:direct-manual", + "ir/direct-manual", (logger) => ParseDirectManual(req.body, logger) ); diff --git a/server/src/score-import/import-types/DOCUMENTATION b/server/src/score-import/import-types/DOCUMENTATION new file mode 100644 index 000000000..e1766774b --- /dev/null +++ b/server/src/score-import/import-types/DOCUMENTATION @@ -0,0 +1,52 @@ +This is temporary documentation for the import mechanisms in this folder. + +# ImportType + +An import type is a string in the following form: + +(mode)/(name). + +## ImportType Modes + +- `file`: A file is uploaded to the server, and data is drew from a buffer. +- `ir`: The data is sent to us in a HTTP Request Body. +- `api`: We request the data on the users behalf from another service. + +## ImportType Names + +- `file/eamusement-iidx-csv`: An IIDX e-amusement CSV file. +- `file/batch-manual`: A JSON file that follows our BATCH-MANUAL specification. + +- `ir/direct-manual`: A request body containing JSON in BATCH-MANUAL form. + +# Parsers + +Parser functions convert the input data into an Iterable. This iterable may +take any form, such as an Array or a Generator which yields paginated API returns. + +They also return some information about the import, such as the game and +playtypes involved. It will also return a Converter Function. + +The iterable itself can contain any style of data. In general, one element +of the iterable will likely correlate with one score. However, in some +scenarios, one element of the iterable may contain multiple scores, such as +iterating over the rows of an IIDX E-amusement CSV, where one row contains +up to 5 separate scores. + +# Converters + +Converter functions are applied upon every member of the iterable. These +convert a member of the iterable into a Dry Score, which is a partial +Kamaitachi Score. + +Converter functions may return the Dry Score, or any of the 'Score Failures' - +A specific set of fail states for a score import, such as the score being +invalid or the appropriate song/chart data for it not existing. + +Converter functions may also return an array of the previous results, in the +case that a single element of the iterable corresponded to multiple scores. + +# Common + +This is for common code - `ir/direct-manual` and `file/batch-manual` use very +similar code paths, so code here is pulled out into a common folder. \ No newline at end of file diff --git a/server/src/score-import/import-types/common/batch-manual/converter.test.ts b/server/src/score-import/import-types/common/batch-manual/converter.test.ts index 7138fa965..c8b640893 100644 --- a/server/src/score-import/import-types/common/batch-manual/converter.test.ts +++ b/server/src/score-import/import-types/common/batch-manual/converter.test.ts @@ -34,7 +34,7 @@ const ktdWrap = (msg: string, game: Game = "iidx", version = null): any => ({ const logger = CreateLogCtx("converter.test.ts"); -const importType = "file/json:batch-manual" as const; +const importType = "file/batch-manual" as const; t.test("#ResolveMatchTypeToKTData", (t) => { t.beforeEach(ResetDBState); diff --git a/server/src/score-import/import-types/file/batch-manual/parser.ts b/server/src/score-import/import-types/file/batch-manual/parser.ts index b693a34bd..365de9d77 100644 --- a/server/src/score-import/import-types/file/batch-manual/parser.ts +++ b/server/src/score-import/import-types/file/batch-manual/parser.ts @@ -24,7 +24,7 @@ function ParseBatchManual( ); } - return ParseBatchManualFromObject(jsonData, "file/json:batch-manual", logger); + return ParseBatchManualFromObject(jsonData, "file/batch-manual", logger); } export default ParseBatchManual; diff --git a/server/src/score-import/import-types/file/eamusement-iidx-csv/converter.ts b/server/src/score-import/import-types/file/eamusement-iidx-csv/converter.ts index e2bff09f2..874c0eae5 100644 --- a/server/src/score-import/import-types/file/eamusement-iidx-csv/converter.ts +++ b/server/src/score-import/import-types/file/eamusement-iidx-csv/converter.ts @@ -58,7 +58,7 @@ export async function EamScoreConverter( if (!ktchiChart) { throw new KTDataNotFoundFailure( `Could not find chart for ${HUMANISED_CHART_TITLE}`, - "file/csv:eamusement-iidx", + "file/eamusement-iidx-csv", data, context ); @@ -127,7 +127,7 @@ export async function EamScoreConverter( service: context.serviceOrigin, comment: null, game: "iidx", - importType: "file/csv:eamusement-iidx", + importType: "file/eamusement-iidx-csv", scoreData: { score: exscore, lamp, @@ -236,7 +236,7 @@ const ConverterFn: ConverterFunction, logger: KtLogger ): ParserFunctionReturnsSync { - return ParseBatchManualFromObject(body, "ir/json:direct-manual", logger); + return ParseBatchManualFromObject(body, "ir/direct-manual", logger); } export default ParseDirectManual; diff --git a/server/src/types.ts b/server/src/types.ts index c6a1fee09..1e4b5b6ef 100644 --- a/server/src/types.ts +++ b/server/src/types.ts @@ -122,13 +122,13 @@ export interface TextDocument extends MongoDBDocument { } export interface ImportTypeDataMap { - "file/csv:eamusement-iidx": IIDXEamusementCSVData; - "file/json:batch-manual": BatchManualScore; - "ir/json:direct-manual": BatchManualScore; + "file/eamusement-iidx-csv": IIDXEamusementCSVData; + "file/batch-manual": BatchManualScore; + "ir/direct-manual": BatchManualScore; } export interface ImportTypeContextMap { - "file/csv:eamusement-iidx": IIDXEamusementCSVContext; - "file/json:batch-manual": BatchManualContext; - "ir/json:direct-manual": BatchManualContext; + "file/eamusement-iidx-csv": IIDXEamusementCSVContext; + "file/batch-manual": BatchManualContext; + "ir/direct-manual": BatchManualContext; }