From 2f3bd8923d0ad2b1d3475ffdbd025d720beb1291 Mon Sep 17 00:00:00 2001 From: zkldi Date: Thu, 28 Oct 2021 19:26:54 +0100 Subject: [PATCH 1/4] Add game as an importdocument field --- server/package.json | 2 +- server/pnpm-lock.yaml | 8 ++++---- .../src/lib/score-import/framework/score-import-main.ts | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/server/package.json b/server/package.json index 627343e69..94ed2ec05 100644 --- a/server/package.json +++ b/server/package.json @@ -77,7 +77,7 @@ "redis": "3.1.2", "rimraf": "3.0.2", "safe-json-stringify": "1.2.0", - "tachi-common": "0.2.34", + "tachi-common": "0.2.35", "ts-node": "10.0.0", "typescript": "4.3.4", "winston": "3.3.3", diff --git a/server/pnpm-lock.yaml b/server/pnpm-lock.yaml index ba065a90f..c2dc8e471 100644 --- a/server/pnpm-lock.yaml +++ b/server/pnpm-lock.yaml @@ -59,7 +59,7 @@ specifiers: rimraf: 3.0.2 safe-json-stringify: 1.2.0 supertest: 6.1.3 - tachi-common: 0.2.34 + tachi-common: 0.2.35 tap: 15.0.9 ts-node: 10.0.0 tsconfig-paths: 3.10.1 @@ -100,7 +100,7 @@ dependencies: redis: 3.1.2 rimraf: 3.0.2 safe-json-stringify: 1.2.0 - tachi-common: 0.2.34 + tachi-common: 0.2.35 ts-node: 10.0.0_83f53b0a0c5616d3fa00ed4e30b9ce1b typescript: 4.3.4 winston: 3.3.3 @@ -4189,8 +4189,8 @@ packages: strip-ansi: 6.0.0 dev: true - /tachi-common/0.2.34: - resolution: {integrity: sha512-qKXIqzMTuT4eNL0Eo3N00fGYDF63bLxvZbf1/7jI+i8pDqJ8Xd1kmSuzNENBr+cp75Krh3qt279xf5oejUOiGw==} + /tachi-common/0.2.35: + resolution: {integrity: sha512-AefVkriGKlpamGA+JTl67qpv4HiZ6sYxCVCZXXvnUXJZiGfsh7dhrqVqXngfxPQjg3mLD81MbZrTNv1HsgwGJQ==} dependencies: monk: 7.3.4 transitivePeerDependencies: diff --git a/server/src/lib/score-import/framework/score-import-main.ts b/server/src/lib/score-import/framework/score-import-main.ts index 5cfcb1a92..5e08eab95 100644 --- a/server/src/lib/score-import/framework/score-import-main.ts +++ b/server/src/lib/score-import/framework/score-import-main.ts @@ -188,6 +188,7 @@ export default async function ScoreImportMain( importType, idStrings: playtypes.map((e) => `${game}:${e}`) as IDStrings[], scoreIDs, + game, errors, importID, timeFinished: Date.now(), From 4d939566dd1c3d15568242d877047f631eba2db8 Mon Sep 17 00:00:00 2001 From: zkldi Date: Thu, 28 Oct 2021 19:27:15 +0100 Subject: [PATCH 2/4] Update imports schemas --- server/src/external/mongo/schemas.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/external/mongo/schemas.ts b/server/src/external/mongo/schemas.ts index 65aabc371..57716c3f0 100644 --- a/server/src/external/mongo/schemas.ts +++ b/server/src/external/mongo/schemas.ts @@ -558,6 +558,7 @@ export const DatabaseSchemas: Record = { idStrings: [p.isIn(allIDStrings)], importID: "string", scoreIDs: ["string"], + game: p.isIn(games), errors: [ { type: "string", From b09ac66b46b7aaac05e761f38361a1bf2cbd8e96 Mon Sep 17 00:00:00 2001 From: zkldi Date: Thu, 28 Oct 2021 20:14:24 +0100 Subject: [PATCH 3/4] Add playtypes to importDoc --- server/package.json | 2 +- server/pnpm-lock.yaml | 8 ++++---- server/src/external/mongo/schemas.ts | 2 ++ .../src/lib/score-import/framework/score-import-main.ts | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/server/package.json b/server/package.json index 94ed2ec05..b12fbea60 100644 --- a/server/package.json +++ b/server/package.json @@ -77,7 +77,7 @@ "redis": "3.1.2", "rimraf": "3.0.2", "safe-json-stringify": "1.2.0", - "tachi-common": "0.2.35", + "tachi-common": "0.2.36", "ts-node": "10.0.0", "typescript": "4.3.4", "winston": "3.3.3", diff --git a/server/pnpm-lock.yaml b/server/pnpm-lock.yaml index c2dc8e471..4d5f167d1 100644 --- a/server/pnpm-lock.yaml +++ b/server/pnpm-lock.yaml @@ -59,7 +59,7 @@ specifiers: rimraf: 3.0.2 safe-json-stringify: 1.2.0 supertest: 6.1.3 - tachi-common: 0.2.35 + tachi-common: 0.2.36 tap: 15.0.9 ts-node: 10.0.0 tsconfig-paths: 3.10.1 @@ -100,7 +100,7 @@ dependencies: redis: 3.1.2 rimraf: 3.0.2 safe-json-stringify: 1.2.0 - tachi-common: 0.2.35 + tachi-common: 0.2.36 ts-node: 10.0.0_83f53b0a0c5616d3fa00ed4e30b9ce1b typescript: 4.3.4 winston: 3.3.3 @@ -4189,8 +4189,8 @@ packages: strip-ansi: 6.0.0 dev: true - /tachi-common/0.2.35: - resolution: {integrity: sha512-AefVkriGKlpamGA+JTl67qpv4HiZ6sYxCVCZXXvnUXJZiGfsh7dhrqVqXngfxPQjg3mLD81MbZrTNv1HsgwGJQ==} + /tachi-common/0.2.36: + resolution: {integrity: sha512-4/enfkwE8HA4x4vrbNMrhLx2j/8JGnEMwAO5b0zSM150chDZiK30vXOmDW1IHSqxoIRZVuIyRqP7aEyUbf7FKA==} dependencies: monk: 7.3.4 transitivePeerDependencies: diff --git a/server/src/external/mongo/schemas.ts b/server/src/external/mongo/schemas.ts index 57716c3f0..564c873bf 100644 --- a/server/src/external/mongo/schemas.ts +++ b/server/src/external/mongo/schemas.ts @@ -559,6 +559,8 @@ export const DatabaseSchemas: Record = { importID: "string", scoreIDs: ["string"], game: p.isIn(games), + // @ts-expect-error We've asserted this is definitely a game. + playtypes: [(self) => p.isIn(GetGameConfig(self.game).validPlaytypes)(self)], errors: [ { type: "string", diff --git a/server/src/lib/score-import/framework/score-import-main.ts b/server/src/lib/score-import/framework/score-import-main.ts index 5e08eab95..0608995cf 100644 --- a/server/src/lib/score-import/framework/score-import-main.ts +++ b/server/src/lib/score-import/framework/score-import-main.ts @@ -188,6 +188,7 @@ export default async function ScoreImportMain( importType, idStrings: playtypes.map((e) => `${game}:${e}`) as IDStrings[], scoreIDs, + playtypes, game, errors, importID, From 89039c6c21154696cb05d4cf399feb8091687bae Mon Sep 17 00:00:00 2001 From: zkldi Date: Thu, 28 Oct 2021 22:18:48 +0100 Subject: [PATCH 4/4] Import endpoints --- .../server/router/api/v1/imports/router.ts | 57 +++++++++++++++++++ server/src/server/router/api/v1/router.ts | 2 + 2 files changed, 59 insertions(+) create mode 100644 server/src/server/router/api/v1/imports/router.ts diff --git a/server/src/server/router/api/v1/imports/router.ts b/server/src/server/router/api/v1/imports/router.ts new file mode 100644 index 000000000..bbdde5bd0 --- /dev/null +++ b/server/src/server/router/api/v1/imports/router.ts @@ -0,0 +1,57 @@ +import { Router } from "express"; +import db from "external/mongo/db"; +import CreateLogCtx from "lib/logger/logger"; +import { GetRelevantSongsAndCharts } from "utils/db"; +import { GetUserWithID } from "utils/user"; + +const router: Router = Router({ mergeParams: true }); + +const logger = CreateLogCtx(__filename); + +router.get("/:importID", async (req, res) => { + const importDoc = await db.imports.findOne({ + importID: req.params.importID, + }); + + if (!importDoc) { + return res.status(404).json({ + success: false, + description: `This import does not exist.`, + }); + } + + const scores = await db.scores.find({ + scoreID: { $in: importDoc.scoreIDs }, + }); + + const { songs, charts } = await GetRelevantSongsAndCharts(scores, importDoc.game); + + const sessions = await db.sessions.find({ + sessionID: { $in: importDoc.createdSessions.map((e) => e.sessionID) }, + }); + + const user = await GetUserWithID(importDoc.userID); + + if (!user) { + logger.severe(`User ${importDoc.userID} doesn't exist, yet has a session?`); + return res.status(500).json({ + success: false, + description: `An internal server error has occured.`, + }); + } + + return res.status(200).json({ + success: true, + description: `Returned info about this session.`, + body: { + scores, + songs, + charts, + sessions, + import: importDoc, + user, + }, + }); +}); + +export default router; diff --git a/server/src/server/router/api/v1/router.ts b/server/src/server/router/api/v1/router.ts index 850b51a00..a88af6b67 100644 --- a/server/src/server/router/api/v1/router.ts +++ b/server/src/server/router/api/v1/router.ts @@ -9,6 +9,7 @@ import searchRouter from "./search/router"; import scoresRouter from "./scores/router"; import sessionsRouter from "./sessions/router"; import oauthRouter from "./oauth/router"; +import importsRouter from "./imports/router"; const router: Router = Router({ mergeParams: true }); @@ -16,6 +17,7 @@ router.use("/admin", adminRouter); router.use("/auth", authRouter); router.use("/status", statusRouter); router.use("/import", importRouter); +router.use("/imports", importsRouter); router.use("/users", usersRouter); router.use("/games", gamesRouter); router.use("/search", searchRouter);