From c1aa9e397af1e1ee513f6168884f23f27663e4c8 Mon Sep 17 00:00:00 2001 From: kitt Date: Tue, 28 Feb 2023 11:34:07 -0500 Subject: [PATCH] add export game function --- src/exporters/mongodb.ts | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/exporters/mongodb.ts b/src/exporters/mongodb.ts index 4e4bec2..afdf00d 100644 --- a/src/exporters/mongodb.ts +++ b/src/exporters/mongodb.ts @@ -1,6 +1,8 @@ import { MongoDB } from "../../deps.ts"; -import { Game, GameExporter } from "../types.ts"; +import { AGENT_VERSION, NSOAPP_VERSION, S3SI_VERSION } from "../constant.ts"; +import { CoopHistoryDetail, ExportResult, Game, GameExporter, VsHistoryDetail } from "../types.ts"; import { parseHistoryDetailId } from "../utils.ts"; +import { FileExporterTypeCommon } from "./file.ts"; export class MongoDBExporter implements GameExporter { name = "mongodb"; @@ -47,4 +49,41 @@ export class MongoDBExporter implements GameExporter { return out; } + + async exportGame(game: Game): Promise { + const uniqueId = this.getGameId(game.detail.id); + + const common = { + // this seems like useful data to store... + // loosely modeled after FileExporterTypeCommon + nsoVersion: NSOAPP_VERSION, + agentVersion: AGENT_VERSION, + s3siVersion: S3SI_VERSION, + exportTime: new Date(), + }; + const body: + { + data: Game, + splatNetData: VsHistoryDetail | CoopHistoryDetail, + gameId: string, + } & typeof common = { + ...common, + data: game, + splatNetData: game.detail, + gameId: uniqueId, + }; + + const isJob = game.type === "CoopInfo"; + + const collection = isJob ? this.jobsCollection : this.battlesCollection; + + const result = await collection.insertOne(body); + + const objectId = result.insertedId; + + return { + status: "success", + url: `https://new.splatoon.catgirlin.space/battle/${objectId.toString()}`, + }; + } }