push mongodb sender
parent
b86fcfc64d
commit
97ebd5ef80
|
|
@ -1,6 +1,7 @@
|
||||||
import { MongoDB } from "../deps.ts";
|
import { MongoDB } from "../deps.ts";
|
||||||
import { DEFAULT_ENV } from "../src/env.ts";
|
import { DEFAULT_ENV } from "../src/env.ts";
|
||||||
import { MongoDBExporter } from "../src/exporters/mongodb.ts";
|
import { MongoDBExporter } from "../src/exporters/mongodb.ts";
|
||||||
|
import { SplashcatExporter } from "../src/exporters/splashcat.ts";
|
||||||
import { FileStateBackend, Profile } from "../src/state.ts";
|
import { FileStateBackend, Profile } from "../src/state.ts";
|
||||||
|
|
||||||
const env = DEFAULT_ENV;
|
const env = DEFAULT_ENV;
|
||||||
|
|
@ -13,6 +14,12 @@ if (!profile.state.mongoDbUri) {
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const splashcatClient = new SplashcatExporter({
|
||||||
|
env,
|
||||||
|
splashcatApiKey: profile.state.splashcatApiKey!,
|
||||||
|
uploadMode: "manual",
|
||||||
|
});
|
||||||
|
|
||||||
const mongoDbClient = new MongoDB.MongoClient(profile.state.mongoDbUri);
|
const mongoDbClient = new MongoDB.MongoClient(profile.state.mongoDbUri);
|
||||||
const battlesCollection = mongoDbClient.db("splashcat").collection("battles");
|
const battlesCollection = mongoDbClient.db("splashcat").collection("battles");
|
||||||
|
|
||||||
|
|
@ -27,31 +34,29 @@ let count = 0;
|
||||||
const erroredBattles = [];
|
const erroredBattles = [];
|
||||||
|
|
||||||
for await (const doc of cursor) {
|
for await (const doc of cursor) {
|
||||||
const { splatNetData, _id } = doc;
|
const { data, splatNetData, _id } = doc;
|
||||||
|
|
||||||
// start time for performance tracking, needs to be very accurate
|
// start time for performance tracking, needs to be very accurate
|
||||||
const startTime = new Date();
|
const startTime = new Date();
|
||||||
|
|
||||||
splatNetData.playedTime = splatNetData.playedTime.toISOString();
|
try {
|
||||||
|
if (data) {
|
||||||
const response = await fetch("http://127.0.0.1:8000/battles/api/upload/", {
|
await splashcatClient.exportGame(data);
|
||||||
method: "POST",
|
} else {
|
||||||
headers: {
|
await splashcatClient.exportGame({
|
||||||
"Content-Type": "application/json",
|
type: "VsInfo",
|
||||||
"Authorization": `Bearer ${profile.state.splashcatApiKey}`,
|
detail: splatNetData,
|
||||||
},
|
bankaraMatchChallenge: null,
|
||||||
body: JSON.stringify({
|
challengeProgress: null,
|
||||||
"data_type": "splatnet3",
|
groupInfo: null,
|
||||||
"battle": splatNetData,
|
listNode: null,
|
||||||
})
|
rankBeforeState: null,
|
||||||
})
|
rankState: null,
|
||||||
|
});
|
||||||
if (!response.ok) {
|
}
|
||||||
console.error(`Failed to upload ${splatNetData.id}`);
|
} catch (e) {
|
||||||
erroredBattles.push({
|
console.log("Failed to export game", e);
|
||||||
id: doc.gameId,
|
erroredBattles.push(e.toString());
|
||||||
error: await response.text(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// end time for performance tracking, needs to be very accurate
|
// end time for performance tracking, needs to be very accurate
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue