add export game function

main
Rosalina 2023-02-28 11:34:07 -05:00
parent 96776b20c8
commit c1aa9e397a
No known key found for this signature in database
1 changed files with 40 additions and 1 deletions

View File

@ -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<ExportResult> {
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()}`,
};
}
}