[~] Added toast exclusion list for API calls.

Removed FetchLogsRequest calls interface (duplicate of base ServerRequest)
This commit is contained in:
Charles Le Maux 2024-08-17 12:03:30 +02:00
parent ef1e5fc2ac
commit 3e329d5bb3

View File

@ -36,10 +36,6 @@ interface CommandRequest extends BaseRequest {
name: string;
}
interface FetchLogsRequest extends BaseRequest {
name: string;
}
enum serviiRequest {
setSubdomain = 'SetSubdomain',
fetchServers = 'FetchServers',
@ -54,6 +50,12 @@ enum serviiRequest {
fetchLogs = 'FetchLogs',
}
const nonToastableCalls: string[] = [
serviiRequest.fetchServers,
serviiRequest.fetchLogs,
];
class serviiApi {
constructor() {}
@ -75,28 +77,30 @@ class serviiApi {
return { return_code: status, message: json };
}
let toastType: 'success' | 'error' | 'info';
let toastColor: string;
if (!nonToastableCalls.includes(endpoint)) {
if (status >= 200 && status < 300) {
toastType = 'success';
} else if (status >= 400 && status < 600) {
toastType = 'error';
} else {
toastType = 'info';
}
let toastType: 'success' | 'error' | 'info';
toast[toastType](json.message, {
position: "top-right",
autoClose: 3500,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "light",
transition: Bounce,
});
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,
});
}
return { return_code: status, message: json.message };
}
@ -119,6 +123,11 @@ class serviiApi {
return this.call(serviiRequest.fetchServers, payload);
}
public static async fetchLogs(name: string): Promise<ApiResponse> {
const payload: ServerRequest = { token: this.token(), name: name };
return this.call(serviiRequest.fetchLogs, payload);
}
public static async accountCreate(): Promise<ApiResponse> {
const payload: BaseRequest = { token: this.token() };
return this.call(serviiRequest.accountCreate, payload);
@ -162,11 +171,6 @@ class serviiApi {
const payload: CommandRequest = { token: this.token(), command: command, name: name };
return this.call(serviiRequest.command, payload);
}
public static async fetchLogs(name: string): Promise<ApiResponse> {
const payload: FetchLogsRequest = { token: this.token(), name: name };
return this.call(serviiRequest.fetchLogs, payload);
}
}
export default serviiApi;