Small fixes

[+] Added maintenance toast
[-] Removed officially unsupported version. (1.12.1 not on amazon's repos anymore)
This commit is contained in:
charleslemaux 2024-09-15 20:18:06 +02:00 committed by GitHub
commit 76acf1daed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 56 additions and 44 deletions

View File

@ -13,7 +13,6 @@ const versions = {
"1.16.1",
"1.13.1",
"1.21.1",
"1.12.1",
"1.15.2",
"1.12.2",
"1.13",

View File

@ -59,54 +59,67 @@ const nonToastableCalls: string[] = [
serviiRequest.fetchPlayersStatus,
];
function toast_status(status: number, message: string) {
let toastType: 'success' | 'error' | 'info' | 'warning';
if (status >= 200 && status < 300) {
toastType = 'success';
} else if (status >= 400 && status < 600) {
toastType = 'error';
} else {
toastType = 'info';
}
if (status == 666) {
toastType = 'warning';
}
toast[toastType](message, {
position: "top-right",
autoClose: 3500,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "light",
transition: Bounce,
});
}
class serviiApi {
constructor() {}
private static async call<T extends BaseRequest>(endpoint: serviiRequest, body: T): Promise<ApiResponse> {
const response = await fetch(`${apiUrl}/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
const status: number = response.status;
const json = await response.json();
if (json.message === undefined) {
if (!(endpoint === serviiRequest.fetchServers)) {
return { return_code: status, message: "Couldn't find an available API" };
}
return { return_code: status, message: json };
}
if (!nonToastableCalls.includes(endpoint)) {
let toastType: 'success' | 'error' | 'info';
if (status >= 200 && status < 300) {
toastType = 'success';
} else if (status >= 400 && status < 600) {
toastType = 'error';
} else {
toastType = 'info';
}
toast[toastType](json.message, {
position: "top-right",
autoClose: 3500,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "light",
transition: Bounce,
const unreachable: string = "Couldn't find an available API";
try {
const response = await fetch(`${apiUrl}/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
const status: number = response.status;
const json = await response.json();
const message = json.message;
if (message === undefined) {
if (!(endpoint === serviiRequest.fetchServers)) {
return {return_code: 503, message: "Couldn't find an available API"};
}
return {return_code: status, message: json};
}
if (!nonToastableCalls.includes(endpoint)) {
toast_status(status, message);
}
return {return_code: status, message: json.message};
} catch (error) {
toast_status(666, unreachable);
return {return_code: 503, message: "Couldn't find an available API"}
}
}
return { return_code: status, message: json.message };
}
constructor() {}
private static token(): string {
const currentUser = getAuth().currentUser;