diff --git a/server/Dockerfile b/server/Dockerfile index 66ce5e92c..8fa52f663 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -5,9 +5,9 @@ FROM node:16 as build WORKDIR /app COPY --chown=node:node . /app -RUN npm install --silent -g pnpm && groupmod -g 1003 node && chown node:node /app +RUN npm install --silent -g pnpm@6 && groupmod -g 1003 node && chown node:node /app USER node -RUN pnpm install --silent && pnpm build && pnpm prune --silent --production && pnpm store prune --silent +RUN pnpm install --silent --frozen-lockfile && pnpm build && pnpm prune --silent --production && pnpm store prune --silent HEALTHCHECK --interval=15s --timeout=5s CMD curl -f http://localhost:8080/api/v1/status || exit 1 ENV NODE_PATH=js/ CMD ["node", "js/main.js"] diff --git a/server/src/lib/score-import/import-types/file/solid-state-squad/parser.test.ts b/server/src/lib/score-import/import-types/file/solid-state-squad/parser.test.ts index 190dd8e7d..52c17f7e9 100644 --- a/server/src/lib/score-import/import-types/file/solid-state-squad/parser.test.ts +++ b/server/src/lib/score-import/import-types/file/solid-state-squad/parser.test.ts @@ -103,6 +103,43 @@ t.test("#ParseSolidStateXML", (t) => { t.end(); }); + t.test("Should parse S3 XML on the chart .59", (t) => { + const res = ParseSolidStateXML( + MockMulterFile(GetKTDataBuffer("./s3/point-five-nine.xml"), "point-five-nine.xml"), + {}, + logger + ); + + t.hasStrict( + res.iterable, + [ + { + id: 187, + diff: 7, + songname: ".59", + styles: "3rd", + exscore: 100, + scorebreakdown: { + justgreats: 50, + greats: 50, + good: 0, + bad: 0, + poor: 4, + }, + mods: {}, + cleartype: "perfect", + date: "2010-10-19 04:54:22", + }, + ], + "Should return the right score in the iterable." + ); + t.equal(res.game, "iidx", "Should return IIDX as the game."); + t.equal(res.classHandler, null, "Should return no class handler."); + t.strictSame(res.context, {}, "Should return no context."); + + t.end(); + }); + t.test("Should reject S3 XML with no scores", (t) => { t.throws( () => diff --git a/server/src/lib/score-import/import-types/file/solid-state-squad/parser.ts b/server/src/lib/score-import/import-types/file/solid-state-squad/parser.ts index e66c340e0..9dc01acaf 100644 --- a/server/src/lib/score-import/import-types/file/solid-state-squad/parser.ts +++ b/server/src/lib/score-import/import-types/file/solid-state-squad/parser.ts @@ -20,7 +20,19 @@ const PR_SOLID_STATE: PrudenceSchema = { { id: p.isPositiveInteger, diff: p.isIn("L7", 7, "A", "B", 5, "L14", 14, "A14", "B14"), - songname: "string", + + // https://github.com/TNG-dev/tachi-server/issues/718 + // The song title '.59' is automatically coerced into a float + // by our XML parser. Despite the fact that it's in a CData field. + // Regardless of the mess that is XML, we need to accept numbers in + // this field, and then convert them back to strings later. + // + // Making a proper solution for this isn't possible, as the bowels + // of the XML parser are inaccessible to us. + // I *hate* XML. + // + // What a disaster. + songname: p.or("string", p.is(0.59)), styles: "string", exscore: p.isPositiveInteger, @@ -53,6 +65,9 @@ const PR_SOLID_STATE: PrudenceSchema = { const xmlParser = new XMLParser(); +// .59 is a song that is interpreted as a float by our XML parser. +type PreStringifiedS3Score = Omit & { songname: 0.59 | string }; + export function ParseSolidStateXML( fileData: Express.Multer.File, body: Record, @@ -102,6 +117,19 @@ export function ParseSolidStateXML( throw new ScoreImportFatalError(400, FormatPrError(err, "Invalid S3 XML.")); } + let scoreData = parsedXML.s3data.scoredata.song as PreStringifiedS3Score[]; + + scoreData = scoreData.map((e) => ({ + ...e, + // Songnames here are either numbers or strings due to a disgusting hack + // @see #718 + // We forcibly convert all these back to strings. + // Note that we can't even use the generic solution .toString, because the + // song title is .59, not 0.59. + // This is genuinely horrific. + songname: e.songname === 0.59 ? ".59" : e.songname, + })); + return { classHandler: null, context: {}, diff --git a/server/src/test-utils/test-data/s3/point-five-nine.xml b/server/src/test-utils/test-data/s3/point-five-nine.xml new file mode 100644 index 000000000..63b9c76a0 --- /dev/null +++ b/server/src/test-utils/test-data/s3/point-five-nine.xml @@ -0,0 +1,47 @@ + + + 3 + + + + + + + + + + 187 + 7 + + + + + + + + + + 174 + 3rd + 1 + 137 + 100 + AA + 9 + + 50 + 50 + 0 + 0 + 4 + + + 2 + T + B + + perfect + 2010-10-19 04:54:22 + + + \ No newline at end of file