Fix API endpoints for saving and retrieving system and session data (#2278)

This commit is contained in:
Frederico Santos 2024-06-16 02:05:49 +01:00 committed by GitHub
parent 766b9132dd
commit 6172f3d574
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 9 deletions

View File

@ -4198,7 +4198,7 @@ export class GameOverPhase extends BattlePhase {
If Offline, execute offlineNewClear(), a localStorage implementation of newClear daily run checks */
if (this.victory) {
if (!Utils.isLocal) {
Utils.apiFetch(`savedata/newclear?slot=${this.scene.sessionSlotId}`, true)
Utils.apiFetch(`savedata/session/newclear?slot=${this.scene.sessionSlotId}`, true)
.then(response => response.json())
.then(newClear => doGameOver(newClear));
} else {

View File

@ -313,7 +313,7 @@ export class GameData {
localStorage.setItem(`data_${loggedInUser.username}`, encrypt(systemData, bypassLogin));
if (!bypassLogin) {
Utils.apiPost(`savedata/update?datatype=${GameDataType.SYSTEM}&clientSessionId=${clientSessionId}`, systemData, undefined, true)
Utils.apiPost(`savedata/system/update?clientSessionId=${clientSessionId}`, systemData, undefined, true)
.then(response => response.text())
.then(error => {
this.scene.ui.savingIcon.hide();
@ -347,7 +347,7 @@ export class GameData {
}
if (!bypassLogin) {
Utils.apiFetch(`savedata/system?clientSessionId=${clientSessionId}`, true)
Utils.apiFetch(`savedata/system/get?clientSessionId=${clientSessionId}`, true)
.then(response => response.text())
.then(response => {
if (!response.length || response[0] !== "{") {
@ -545,7 +545,7 @@ export class GameData {
return true;
}
const response = await Utils.apiPost("savedata/system/verify", JSON.stringify({ clientSessionId: clientSessionId }), undefined, true)
const response = await Utils.apiFetch(`savedata/system/verify?clientSessionId=${clientSessionId}`, true)
.then(response => response.json());
if (!response.valid) {
@ -815,7 +815,7 @@ export class GameData {
};
if (!bypassLogin && !localStorage.getItem(`sessionData${slotId ? slotId : ""}_${loggedInUser.username}`)) {
Utils.apiFetch(`savedata/session?slot=${slotId}&clientSessionId=${clientSessionId}`, true)
Utils.apiFetch(`savedata/session/get?slot=${slotId}&clientSessionId=${clientSessionId}`, true)
.then(response => response.text())
.then(async response => {
if (!response.length || response[0] !== "{") {
@ -963,7 +963,7 @@ export class GameData {
if (success !== null && !success) {
return resolve(false);
}
Utils.apiFetch(`savedata/delete?datatype=${GameDataType.SESSION}&slot=${slotId}&clientSessionId=${clientSessionId}`, true).then(response => {
Utils.apiFetch(`savedata/session/delete?slot=${slotId}&clientSessionId=${clientSessionId}`, true).then(response => {
if (response.ok) {
loggedInUser.lastSessionSlot = -1;
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ""}_${loggedInUser.username}`);
@ -1027,7 +1027,7 @@ export class GameData {
return resolve([false, false]);
}
const sessionData = this.getSessionSaveData(scene);
Utils.apiPost(`savedata/clear?slot=${slotId}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`, JSON.stringify(sessionData), undefined, true).then(response => {
Utils.apiPost(`savedata/session/clear?slot=${slotId}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`, JSON.stringify(sessionData), undefined, true).then(response => {
if (response.ok) {
loggedInUser.lastSessionSlot = -1;
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ""}_${loggedInUser.username}`);
@ -1184,7 +1184,7 @@ export class GameData {
link.remove();
};
if (!bypassLogin && dataType < GameDataType.SETTINGS) {
Utils.apiFetch(`savedata/${dataType === GameDataType.SYSTEM ? "system" : "session"}?clientSessionId=${clientSessionId}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ""}`, true)
Utils.apiFetch(`savedata/${dataType === GameDataType.SYSTEM ? "system" : "session"}/get?clientSessionId=${clientSessionId}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ""}`, true)
.then(response => response.text())
.then(response => {
if (!response.length || response[0] !== "{") {
@ -1264,7 +1264,13 @@ export class GameData {
if (!success) {
return displayError(`Could not contact the server. Your ${dataName} data could not be imported.`);
}
Utils.apiPost(`savedata/update?datatype=${dataType}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ""}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`, dataStr, undefined, true)
let url: string;
if (dataType === GameDataType.SESSION) {
url = `savedata/session/update?slot=${slotId}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`;
} else {
url = `savedata/system/update?trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`;
}
Utils.apiPost(url, dataStr, undefined, true)
.then(response => response.text())
.then(error => {
if (error) {