add summary exporter and fix notExported check
parent
eb91b8a171
commit
3e1a90dc45
|
|
@ -1,6 +1,6 @@
|
||||||
import { MongoDB } from "../../deps.ts";
|
import { MongoDB } from "../../deps.ts";
|
||||||
import { AGENT_VERSION, NSOAPP_VERSION, S3SI_VERSION } from "../constant.ts";
|
import { AGENT_VERSION, NSOAPP_VERSION, S3SI_VERSION } from "../constant.ts";
|
||||||
import { CoopHistoryDetail, ExportResult, Game, GameExporter, VsHistoryDetail } from "../types.ts";
|
import { CoopHistoryDetail, ExportResult, Game, GameExporter, Summary, VsHistoryDetail } from "../types.ts";
|
||||||
import { parseHistoryDetailId } from "../utils.ts";
|
import { parseHistoryDetailId } from "../utils.ts";
|
||||||
import { FileExporterTypeCommon } from "./file.ts";
|
import { FileExporterTypeCommon } from "./file.ts";
|
||||||
|
|
||||||
|
|
@ -10,14 +10,16 @@ export class MongoDBExporter implements GameExporter {
|
||||||
mongoDb: MongoDB.Db;
|
mongoDb: MongoDB.Db;
|
||||||
battlesCollection: MongoDB.Collection;
|
battlesCollection: MongoDB.Collection;
|
||||||
jobsCollection: MongoDB.Collection;
|
jobsCollection: MongoDB.Collection;
|
||||||
|
summariesCollection: MongoDB.Collection;
|
||||||
constructor(private mongoDbUri: string) {
|
constructor(private mongoDbUri: string) {
|
||||||
this.mongoDbClient = new MongoDB.MongoClient(mongoDbUri);
|
this.mongoDbClient = new MongoDB.MongoClient(mongoDbUri);
|
||||||
this.mongoDb = this.mongoDbClient.db("splashcat");
|
this.mongoDb = this.mongoDbClient.db("splashcat");
|
||||||
this.battlesCollection = this.mongoDb.collection("battles");
|
this.battlesCollection = this.mongoDb.collection("battles");
|
||||||
this.jobsCollection = this.mongoDb.collection("jobs");
|
this.jobsCollection = this.mongoDb.collection("jobs");
|
||||||
|
this.summariesCollection = this.mongoDb.collection("summaries");
|
||||||
}
|
}
|
||||||
|
|
||||||
getGameId(id: string) { // very similar to the file exporter
|
static getGameId(id: string) { // very similar to the file exporter
|
||||||
const { uid, timestamp } = parseHistoryDetailId(id);
|
const { uid, timestamp } = parseHistoryDetailId(id);
|
||||||
|
|
||||||
return `${uid}_${timestamp}Z`;
|
return `${uid}_${timestamp}Z`;
|
||||||
|
|
@ -32,12 +34,10 @@ export class MongoDBExporter implements GameExporter {
|
||||||
// countOldStorage can be removed later eventually when all old documents
|
// countOldStorage can be removed later eventually when all old documents
|
||||||
// are gone from SplatNet 3
|
// are gone from SplatNet 3
|
||||||
const countOldStorage = await collection.countDocuments({
|
const countOldStorage = await collection.countDocuments({
|
||||||
splatNetData: {
|
"splatNetData.id": id,
|
||||||
id: id,
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const uniqueId = this.getGameId(id);
|
const uniqueId = MongoDBExporter.getGameId(id);
|
||||||
const countNewStorage = await collection.countDocuments({
|
const countNewStorage = await collection.countDocuments({
|
||||||
gameId: uniqueId,
|
gameId: uniqueId,
|
||||||
});
|
});
|
||||||
|
|
@ -51,7 +51,7 @@ export class MongoDBExporter implements GameExporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
async exportGame(game: Game): Promise<ExportResult> {
|
async exportGame(game: Game): Promise<ExportResult> {
|
||||||
const uniqueId = this.getGameId(game.detail.id);
|
const uniqueId = MongoDBExporter.getGameId(game.detail.id);
|
||||||
|
|
||||||
const common = {
|
const common = {
|
||||||
// this seems like useful data to store...
|
// this seems like useful data to store...
|
||||||
|
|
@ -59,7 +59,7 @@ export class MongoDBExporter implements GameExporter {
|
||||||
nsoVersion: NSOAPP_VERSION,
|
nsoVersion: NSOAPP_VERSION,
|
||||||
agentVersion: AGENT_VERSION,
|
agentVersion: AGENT_VERSION,
|
||||||
s3siVersion: S3SI_VERSION,
|
s3siVersion: S3SI_VERSION,
|
||||||
exportTime: new Date(),
|
exportDate: new Date(),
|
||||||
};
|
};
|
||||||
const body:
|
const body:
|
||||||
{
|
{
|
||||||
|
|
@ -86,4 +86,17 @@ export class MongoDBExporter implements GameExporter {
|
||||||
url: `https://new.splatoon.catgirlin.space/battle/${objectId.toString()}`,
|
url: `https://new.splatoon.catgirlin.space/battle/${objectId.toString()}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async exportSummary(summary: Summary): Promise<ExportResult> {
|
||||||
|
const id = summary.uid;
|
||||||
|
|
||||||
|
await this.summariesCollection.insertOne({
|
||||||
|
summaryId: id,
|
||||||
|
...summary,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "success",
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue