diff --git a/server/package.json b/server/package.json index 627343e69..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.34", + "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 ba065a90f..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.34 + 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.34 + 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.34: - resolution: {integrity: sha512-qKXIqzMTuT4eNL0Eo3N00fGYDF63bLxvZbf1/7jI+i8pDqJ8Xd1kmSuzNENBr+cp75Krh3qt279xf5oejUOiGw==} + /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 65aabc371..564c873bf 100644 --- a/server/src/external/mongo/schemas.ts +++ b/server/src/external/mongo/schemas.ts @@ -558,6 +558,9 @@ export const DatabaseSchemas: Record = { idStrings: [p.isIn(allIDStrings)], 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 5cfcb1a92..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,8 @@ export default async function ScoreImportMain( importType, idStrings: playtypes.map((e) => `${game}:${e}`) as IDStrings[], scoreIDs, + playtypes, + game, errors, importID, timeFinished: Date.now(), 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);