migrate updateAllSavedata to api

This commit is contained in:
flx-sta 2024-10-03 17:35:47 -07:00
parent ebf897822e
commit 3e3315d223
4 changed files with 32 additions and 3 deletions

View File

@ -6,3 +6,6 @@ export const USE_SEASONAL_SPLASH_MESSAGES: boolean = false;
/** Name of the session ID cookie */ /** Name of the session ID cookie */
export const SESSION_ID_COOKIE_NAME: string = "pokerogue_sessionId"; export const SESSION_ID_COOKIE_NAME: string = "pokerogue_sessionId";
/** Max value for an integer attribute in {@linkcode SystemSaveData} */
export const MAX_INT_ATTR_VALUE = 0x80000000;

View File

@ -1,12 +1,13 @@
import type { PokerogueApiClearSessionData } from "#app/@types/pokerogue-api"; import type { PokerogueApiClearSessionData } from "#app/@types/pokerogue-api";
import { loggedInUser } from "#app/account"; import { loggedInUser } from "#app/account";
import { SESSION_ID_COOKIE_NAME } from "#app/constants"; import { MAX_INT_ATTR_VALUE, SESSION_ID_COOKIE_NAME } from "#app/constants";
import type { SessionSaveData } from "#app/system/game-data"; import type { SessionSaveData } from "#app/system/game-data";
import type { RankingEntry, ScoreboardCategory } from "#app/ui/daily-run-scoreboard"; import type { RankingEntry, ScoreboardCategory } from "#app/ui/daily-run-scoreboard";
import { getCookie, removeCookie, setCookie } from "#app/utils"; import { getCookie, removeCookie, setCookie } from "#app/utils";
import type { AccountInfoResponse } from "./models/AccountInfo"; import type { AccountInfoResponse } from "./models/AccountInfo";
import type { AccountLoginRequest, AccountLoginResponse } from "./models/AccountLogin"; import type { AccountLoginRequest, AccountLoginResponse } from "./models/AccountLogin";
import type { TitleStatsResponse } from "./models/TitleStats"; import type { TitleStatsResponse } from "./models/TitleStats";
import type { UpdateAllSavedataRequest } from "./models/UpdateAllSavedata";
import type { VerifySavedataResponse } from "./models/VerifySavedata"; import type { VerifySavedataResponse } from "./models/VerifySavedata";
type DataType = "json" | "form-urlencoded"; type DataType = "json" | "form-urlencoded";
@ -289,6 +290,24 @@ export class Api {
return null; return null;
} }
/**
* Update all savedata
* @param bodyData The {@linkcode UpdateAllSavedataRequest | request data} to send
* @returns an error message if something went wrong
*/
public async updateAllSavedata(bodyData: UpdateAllSavedataRequest) {
try {
const rawBodyData = JSON.stringify(bodyData, (_k: any, v: any) =>
typeof v === "bigint" ? (v <= MAX_INT_ATTR_VALUE ? Number(v) : v.toString()) : v
);
const response = await this.doPost<string>("/savedata/updateall", rawBodyData);
return await response.text();
} catch (err) {
console.warn("Could not update all savedata!", err);
return null;
}
}
/** /**
* Get the daily rankings for a {@linkcode ScoreboardCategory}. * Get the daily rankings for a {@linkcode ScoreboardCategory}.
* @param category The {@linkcode ScoreboardCategory} to fetch. * @param category The {@linkcode ScoreboardCategory} to fetch.

View File

@ -0,0 +1,8 @@
import type { SessionSaveData, SystemSaveData } from "#app/system/game-data";
export interface UpdateAllSavedataRequest {
system: SystemSaveData;
session: SessionSaveData;
sessionSlotId: number;
clientSessionId: string;
}

View File

@ -1309,8 +1309,7 @@ export class GameData {
console.debug("Session data saved"); console.debug("Session data saved");
if (!bypassLogin && sync) { if (!bypassLogin && sync) {
Utils.apiPost("savedata/updateall", JSON.stringify(request, (k: any, v: any) => typeof v === "bigint" ? v <= maxIntAttrValue ? Number(v) : v.toString() : v), undefined, true) api.updateAllSavedata(request)
.then(response => response.text())
.then(error => { .then(error => {
if (sync) { if (sync) {
this.scene.lastSavePlayTime = 0; this.scene.lastSavePlayTime = 0;