From 4c6b741eae4b63fe0cbb633ec02e8ef6ea1187c1 Mon Sep 17 00:00:00 2001 From: zkldi Date: Fri, 21 May 2021 14:10:27 +0100 Subject: [PATCH] POST /replays --- server/src/api/ir/usc/usc.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/server/src/api/ir/usc/usc.ts b/server/src/api/ir/usc/usc.ts index 8955c0644..5178b5274 100644 --- a/server/src/api/ir/usc/usc.ts +++ b/server/src/api/ir/usc/usc.ts @@ -23,6 +23,7 @@ import { GetPBOnChart, GetServerRecordOnChart } from "../../../common/scores"; import crypto from "crypto"; import { Random20Hex } from "../../../common/util"; import { USCIR_ADJACENT_SCORE_N, USCIR_MAX_LEADERBOARD_N } from "../../../constants/usc-ir"; +import { CreateMulterSingleUploadMiddleware } from "../../../common/multer"; const logger = CreateLogCtx("usc.ts"); @@ -313,4 +314,39 @@ router.post("/scores", async (req, res) => { } }); +/** + * Used to submit the replay for a given score when requested by the server. + * https://uscir.readthedocs.io/en/latest/endpoints/replay-submit.html + * @name POST /api/ir/usc/replays + */ +router.post("/replays", CreateMulterSingleUploadMiddleware("replay"), async (req, res) => { + if (typeof req.body.identifier !== "string") { + return res.status(200).json({ + statusCode: STATUS_CODES.BAD_REQ, + description: "No Identifier Provided.", + }); + } + + const correspondingScore = await db.scores.findOne({ + userID: req[SYMBOL_KtchiData]!.uscAuthDoc!.userID, + game: "usc", + "scoreMeta.replayID": req.body.identifier, + }); + + if (!correspondingScore) { + return res.status(200).json({ + statusCode: STATUS_CODES.NOT_FOUND, + description: "No score corresponds to this identifier.", + }); + } + + // @todo #113 Properly store replays sent with POST /replays. + + return res.status(200).json({ + statusCode: STATUS_CODES.SUCCESS, + description: "Saved replay.", + body: null, + }); +}); + export default router;