Use new save endpoints
This commit is contained in:
parent
8a0eaa0009
commit
523011f9ed
|
@ -301,7 +301,7 @@ export class GameData {
|
||||||
localStorage.setItem(`data_${loggedInUser.username}`, encrypt(systemData, bypassLogin));
|
localStorage.setItem(`data_${loggedInUser.username}`, encrypt(systemData, bypassLogin));
|
||||||
|
|
||||||
if (!bypassLogin) {
|
if (!bypassLogin) {
|
||||||
Utils.apiPost(`savedata/update?datatype=${GameDataType.SYSTEM}&clientSessionId=${clientSessionId}`, systemData, undefined, true)
|
Utils.apiPut(`savedata/system?clientSessionId=${clientSessionId}`, systemData, undefined)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(error => {
|
.then(error => {
|
||||||
this.scene.ui.savingIcon.hide();
|
this.scene.ui.savingIcon.hide();
|
||||||
|
@ -951,7 +951,7 @@ export class GameData {
|
||||||
if (success !== null && !success) {
|
if (success !== null && !success) {
|
||||||
return resolve(false);
|
return resolve(false);
|
||||||
}
|
}
|
||||||
Utils.apiFetch(`savedata/delete?datatype=${GameDataType.SESSION}&slot=${slotId}&clientSessionId=${clientSessionId}`, true).then(response => {
|
Utils.apiDelete(`savedata/session?slot=${slotId}&clientSessionId=${clientSessionId}`).then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
loggedInUser.lastSessionSlot = -1;
|
loggedInUser.lastSessionSlot = -1;
|
||||||
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ""}_${loggedInUser.username}`);
|
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ""}_${loggedInUser.username}`);
|
||||||
|
@ -1124,7 +1124,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)
|
Utils.apiPut("savedata/updateall", JSON.stringify(request, (k: any, v: any) => typeof v === "bigint" ? v <= maxIntAttrValue ? Number(v) : v.toString() : v), undefined)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(error => {
|
.then(error => {
|
||||||
if (sync) {
|
if (sync) {
|
||||||
|
@ -1266,7 +1266,7 @@ export class GameData {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
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.`);
|
||||||
}
|
}
|
||||||
Utils.apiPost(`savedata/update?datatype=${dataType}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ""}&trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`, dataStr, undefined, true)
|
Utils.apiPut(`savedata/${dataType === GameDataType.SESSION ? `session?slot=${slotId}&` : "system?"}trainerId=${this.trainerId}&secretId=${this.secretId}&clientSessionId=${clientSessionId}`, dataStr, undefined)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(error => {
|
.then(error => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
28
src/utils.ts
28
src/utils.ts
|
@ -361,6 +361,34 @@ export function apiPost(path: string, data?: any, contentType: string = "applica
|
||||||
}) : new Promise(() => {});
|
}) : new Promise(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function apiPut(path: string, data?: any, contentType: string = "application/json"): Promise<Response> {
|
||||||
|
return (isLocal && isLocalServerConnected) || !isLocal ? new Promise((resolve, reject) => {
|
||||||
|
const headers = {
|
||||||
|
"Content-Type": contentType,
|
||||||
|
};
|
||||||
|
const sId = getCookie(sessionIdKey);
|
||||||
|
if (sId) {
|
||||||
|
headers["Authorization"] = sId;
|
||||||
|
}
|
||||||
|
fetch(`${apiUrl}/${path}`, { method: "PUT", headers: headers, body: data })
|
||||||
|
.then(response => resolve(response))
|
||||||
|
.catch(err => reject(err));
|
||||||
|
}) : new Promise(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function apiDelete(path: string): Promise<Response> {
|
||||||
|
return (isLocal && isLocalServerConnected) || !isLocal ? new Promise((resolve, reject) => {
|
||||||
|
const headers = {};
|
||||||
|
const sId = getCookie(sessionIdKey);
|
||||||
|
if (sId) {
|
||||||
|
headers["Authorization"] = sId;
|
||||||
|
}
|
||||||
|
fetch(`${apiUrl}/${path}`, { method: "DELETE", headers: headers})
|
||||||
|
.then(response => resolve(response))
|
||||||
|
.catch(err => reject(err));
|
||||||
|
}) : new Promise(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
export class BooleanHolder {
|
export class BooleanHolder {
|
||||||
public value: boolean;
|
public value: boolean;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue