feat: add login to export-geardata
parent
6fcebb07bd
commit
068daa15bd
|
|
@ -2,17 +2,19 @@
|
||||||
* Export your gear database to json format used in:
|
* Export your gear database to json format used in:
|
||||||
* https://leanny.github.io/splat3seedchecker/#/settings
|
* https://leanny.github.io/splat3seedchecker/#/settings
|
||||||
*
|
*
|
||||||
* This script get token from `./profile.json`. And export geardata
|
* This script get token from `./profile.json` or login interactively.
|
||||||
* to `./geardata_${timestamp}.json`.
|
* And export geardata to `./geardata_${timestamp}.json`.
|
||||||
* Make sure to update token before running this script.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Murmurhash3 from "https://deno.land/x/murmurhash@v1.0.0/mod.ts";
|
import Murmurhash3 from "https://deno.land/x/murmurhash@v1.0.0/mod.ts";
|
||||||
import { base64 } from "../deps.ts";
|
import { base64 } from "../deps.ts";
|
||||||
|
import { getBulletToken, getGToken, loginManually } from "../src/iksm.ts";
|
||||||
import { getGears, getLatestBattleHistoriesQuery } from "../src/splatnet3.ts";
|
import { getGears, getLatestBattleHistoriesQuery } from "../src/splatnet3.ts";
|
||||||
import { FileStateBackend } from "../src/state.ts";
|
import { DEFAULT_STATE, FileStateBackend, State } from "../src/state.ts";
|
||||||
import { parseHistoryDetailId } from "../src/utils.ts";
|
import { parseHistoryDetailId } from "../src/utils.ts";
|
||||||
|
|
||||||
|
const PROFILE_PATH = "./profile.json";
|
||||||
|
|
||||||
function encryptKey(uid: string) {
|
function encryptKey(uid: string) {
|
||||||
const hasher = new Murmurhash3();
|
const hasher = new Murmurhash3();
|
||||||
hasher.hash(uid);
|
hasher.hash(uid);
|
||||||
|
|
@ -27,11 +29,55 @@ function encryptKey(uid: string) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = await new FileStateBackend("./profile.json").read();
|
// https://stackoverflow.com/questions/56658114/how-can-one-check-if-a-file-or-directory-exists-using-deno
|
||||||
|
const exists = async (filename: string): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
await Deno.stat(filename);
|
||||||
|
// successful, file or directory must exist
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Deno.errors.NotFound) {
|
||||||
|
// file or directory does not exist
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
// unexpected error, maybe permissions, pass it along
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let state: State;
|
||||||
|
|
||||||
|
if (await exists(PROFILE_PATH)) {
|
||||||
|
state = await new FileStateBackend(PROFILE_PATH).read();
|
||||||
|
} else {
|
||||||
|
const sessionToken = await loginManually();
|
||||||
|
|
||||||
|
const { webServiceToken, userCountry, userLang } = await getGToken({
|
||||||
|
fApi: DEFAULT_STATE.fGen,
|
||||||
|
sessionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
const bulletToken = await getBulletToken({
|
||||||
|
webServiceToken,
|
||||||
|
userLang,
|
||||||
|
userCountry,
|
||||||
|
});
|
||||||
|
|
||||||
|
state = {
|
||||||
|
...DEFAULT_STATE,
|
||||||
|
loginState: {
|
||||||
|
sessionToken,
|
||||||
|
gToken: webServiceToken,
|
||||||
|
bulletToken,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const [latest, gears] = [getLatestBattleHistoriesQuery(state), getGears(state)];
|
||||||
|
|
||||||
console.log("Fetching uid...");
|
console.log("Fetching uid...");
|
||||||
const { latestBattleHistories: { historyGroups } } =
|
const { latestBattleHistories: { historyGroups } } = await latest;
|
||||||
await getLatestBattleHistoriesQuery(state);
|
|
||||||
|
|
||||||
const id = historyGroups.nodes?.[0].historyDetails.nodes?.[0].id;
|
const id = historyGroups.nodes?.[0].historyDetails.nodes?.[0].id;
|
||||||
|
|
||||||
|
|
@ -43,7 +89,7 @@ if (!id) {
|
||||||
const { uid } = parseHistoryDetailId(id);
|
const { uid } = parseHistoryDetailId(id);
|
||||||
|
|
||||||
console.log("Fetching gears...");
|
console.log("Fetching gears...");
|
||||||
const data = await getGears(state);
|
const data = await gears;
|
||||||
const timestamp = Math.floor(new Date().getTime() / 1000);
|
const timestamp = Math.floor(new Date().getTime() / 1000);
|
||||||
|
|
||||||
await Deno.writeTextFile(
|
await Deno.writeTextFile(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue