mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-14 01:59:05 +03:00
Merge pull request #378 from TNG-dev:zkldi/issue-375-Import-Endpoints
Import Endpoints
This commit is contained in:
+1
-1
@@ -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",
|
||||
|
||||
Generated
+4
-4
@@ -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:
|
||||
|
||||
Vendored
+3
@@ -558,6 +558,9 @@ export const DatabaseSchemas: Record<Databases, ValidatorFunction> = {
|
||||
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",
|
||||
|
||||
@@ -188,6 +188,8 @@ export default async function ScoreImportMain<D, C>(
|
||||
importType,
|
||||
idStrings: playtypes.map((e) => `${game}:${e}`) as IDStrings[],
|
||||
scoreIDs,
|
||||
playtypes,
|
||||
game,
|
||||
errors,
|
||||
importID,
|
||||
timeFinished: Date.now(),
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user