mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-01 05:52:17 +02:00
migrate updateSessionSavedata
to api
This commit is contained in:
parent
3e3315d223
commit
9df8a616d4
@ -8,6 +8,8 @@ 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 { UpdateAllSavedataRequest } from "./models/UpdateAllSavedata";
|
||||||
|
import type { UpdateSessionSavedataRequest } from "./models/UpdateSessionSavedata";
|
||||||
|
import type { UpdateSystemSavedataRequest } from "./models/UpdateSystemSavedata";
|
||||||
import type { VerifySavedataResponse } from "./models/VerifySavedata";
|
import type { VerifySavedataResponse } from "./models/VerifySavedata";
|
||||||
|
|
||||||
type DataType = "json" | "form-urlencoded";
|
type DataType = "json" | "form-urlencoded";
|
||||||
@ -66,10 +68,7 @@ export class Api {
|
|||||||
try {
|
try {
|
||||||
const response = await this.doPost<AccountLoginRequest>(
|
const response = await this.doPost<AccountLoginRequest>(
|
||||||
"/account/login",
|
"/account/login",
|
||||||
{
|
{ username, password },
|
||||||
username,
|
|
||||||
password,
|
|
||||||
},
|
|
||||||
"form-urlencoded"
|
"form-urlencoded"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -186,17 +185,17 @@ export class Api {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a system savedata.
|
* Update a system savedata.
|
||||||
* @param clientSessionId The savedata session ID
|
* @param updateData The {@linkcode UpdateSystemSavedataRequest} to send
|
||||||
* @param rawSystemData The raw {@linkcode SystemSaveData}
|
* @param rawSystemData The raw {@linkcode SystemSaveData}
|
||||||
* @returns an error message if something went wrong
|
* @returns an error message if something went wrong
|
||||||
*/
|
*/
|
||||||
public async updateSystemSavedata(clientSessionId: string, rawSystemData: string) {
|
public async updateSystemSavedata(updateData: UpdateSystemSavedataRequest, rawSystemData: string) {
|
||||||
try {
|
try {
|
||||||
const params = new URLSearchParams();
|
const updateArr = Object.entries(updateData).map(([key, value]) => [key, String(value)]);
|
||||||
params.append("clientSessionId", clientSessionId);
|
const params = new URLSearchParams(updateArr);
|
||||||
const response = await this.doPost<string>(`/savedata/system/update?${params}`, rawSystemData);
|
const response = await this.doPost<string>(`/savedata/system/update?${params}`, rawSystemData);
|
||||||
|
|
||||||
return (await response.json()) as string;
|
return await response.text();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn("Could not update system savedata!", err);
|
console.warn("Could not update system savedata!", err);
|
||||||
}
|
}
|
||||||
@ -225,6 +224,27 @@ export class Api {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a session savedata.
|
||||||
|
* @param updateData The {@linkcode UpdateSessionSavedataRequest} to send
|
||||||
|
* @param rawSavedata The raw savedata (as `string`)
|
||||||
|
* @returns an error message if something went wrong
|
||||||
|
*/
|
||||||
|
public async updateSessionSavedata(updateData: UpdateSessionSavedataRequest, rawSavedata: string) {
|
||||||
|
try {
|
||||||
|
const updateArr = Object.entries(updateData).map(([key, value]) => [key, String(value)]);
|
||||||
|
const params = new URLSearchParams(updateArr);
|
||||||
|
|
||||||
|
const response = await this.doPost<string>(`/savedata/session/update?${params}`, rawSavedata);
|
||||||
|
|
||||||
|
return await response.text();
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("Could not update session savedata!", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a session savedata slot.
|
* Delete a session savedata slot.
|
||||||
* @param slotId The slot ID to load
|
* @param slotId The slot ID to load
|
||||||
|
6
src/plugins/api/models/UpdateSessionSavedata.ts
Normal file
6
src/plugins/api/models/UpdateSessionSavedata.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export class UpdateSessionSavedataRequest {
|
||||||
|
slot: number;
|
||||||
|
trainerId: number;
|
||||||
|
secretId: number;
|
||||||
|
clientSessionId: string;
|
||||||
|
}
|
5
src/plugins/api/models/UpdateSystemSavedata.ts
Normal file
5
src/plugins/api/models/UpdateSystemSavedata.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export class UpdateSystemSavedataRequest {
|
||||||
|
clientSessionId: string;
|
||||||
|
trainerId?: number;
|
||||||
|
secretId?: number;
|
||||||
|
}
|
@ -397,7 +397,7 @@ export class GameData {
|
|||||||
localStorage.setItem(`data_${loggedInUser?.username}`, encrypt(systemData, bypassLogin));
|
localStorage.setItem(`data_${loggedInUser?.username}`, encrypt(systemData, bypassLogin));
|
||||||
|
|
||||||
if (!bypassLogin) {
|
if (!bypassLogin) {
|
||||||
api.updateSystemSavedata(clientSessionId, systemData)
|
api.updateSystemSavedata({clientSessionId}, systemData)
|
||||||
.then(error => {
|
.then(error => {
|
||||||
this.scene.ui.savingIcon.hide();
|
this.scene.ui.savingIcon.hide();
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -1454,14 +1454,14 @@ export class GameData {
|
|||||||
if (!success[0]) {
|
if (!success[0]) {
|
||||||
return displayError(`Could not contact the server. Your ${dataName} data could not be imported.`);
|
return displayError(`Could not contact the server. Your ${dataName} data could not be imported.`);
|
||||||
}
|
}
|
||||||
let url: string;
|
const { trainerId, secretId } = this;
|
||||||
|
let updatePromise: Promise<string | null>;
|
||||||
if (dataType === GameDataType.SESSION) {
|
if (dataType === GameDataType.SESSION) {
|
||||||
url = `savedata/session/update?slot=${slotId}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`;
|
updatePromise = api.updateSessionSavedata({slot: slotId, trainerId, secretId, clientSessionId}, dataStr);
|
||||||
} else {
|
} else {
|
||||||
url = `savedata/system/update?trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`;
|
updatePromise = api.updateSystemSavedata({trainerId, secretId, clientSessionId}, dataStr);
|
||||||
}
|
}
|
||||||
Utils.apiPost(url, dataStr, undefined, true)
|
updatePromise
|
||||||
.then(response => response.text())
|
|
||||||
.then(error => {
|
.then(error => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
Loading…
Reference in New Issue
Block a user