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