mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2024-11-29 02:06:07 +00:00
migrate updateAllSavedata to api
This commit is contained in:
parent
ebf897822e
commit
3e3315d223
@ -6,3 +6,6 @@ export const USE_SEASONAL_SPLASH_MESSAGES: boolean = false;
|
||||
|
||||
/** Name of the session ID cookie */
|
||||
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;
|
||||
|
@ -1,12 +1,13 @@
|
||||
import type { PokerogueApiClearSessionData } from "#app/@types/pokerogue-api";
|
||||
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 { RankingEntry, ScoreboardCategory } from "#app/ui/daily-run-scoreboard";
|
||||
import { getCookie, removeCookie, setCookie } from "#app/utils";
|
||||
import type { AccountInfoResponse } from "./models/AccountInfo";
|
||||
import type { AccountLoginRequest, AccountLoginResponse } from "./models/AccountLogin";
|
||||
import type { TitleStatsResponse } from "./models/TitleStats";
|
||||
import type { UpdateAllSavedataRequest } from "./models/UpdateAllSavedata";
|
||||
import type { VerifySavedataResponse } from "./models/VerifySavedata";
|
||||
|
||||
type DataType = "json" | "form-urlencoded";
|
||||
@ -289,6 +290,24 @@ export class Api {
|
||||
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}.
|
||||
* @param category The {@linkcode ScoreboardCategory} to fetch.
|
||||
|
8
src/plugins/api/models/UpdateAllSavedata.ts
Normal file
8
src/plugins/api/models/UpdateAllSavedata.ts
Normal 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;
|
||||
}
|
@ -1309,8 +1309,7 @@ export class GameData {
|
||||
console.debug("Session data saved");
|
||||
|
||||
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)
|
||||
.then(response => response.text())
|
||||
api.updateAllSavedata(request)
|
||||
.then(error => {
|
||||
if (sync) {
|
||||
this.scene.lastSavePlayTime = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user