Files
bot_Tamiseur/src/utils/amp.ts
Zachary Guénot ddd617317c
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 6m16s
Réécriture complète 4.0
2025-06-09 16:29:12 +02:00

58 lines
2.8 KiB
TypeScript

import axios from "axios"
import type { AxiosResponse } from "axios"
import type { APIResponse } from "@/types"
import type { LoginDetails } from "@/types/amp"
export const ADSModule = {
async GetInstances(host: string, SESSIONID: string) {
return axios.post(host + "/API/ADSModule/GetInstances", { SESSIONID })
.then((response: AxiosResponse<APIResponse>) => {
if (!Array.isArray(response.data)) return { status: "fail", data: response.data }
return { status: "success", data: response.data }
})
.catch((error: unknown) => { console.error(error); return { status: "error", data: error } })
},
async ManageInstance(host: string, SESSIONID: string, InstanceId: string) {
return axios.post(host + "/API/ADSModule/ManageInstance", { SESSIONID, InstanceId })
.then((response: AxiosResponse<APIResponse>) => {
if (!response.data.result) return { status: "fail", data: response.data }
return { status: "success", data: response.data }
})
.catch((error: unknown) => { console.error(error); return { status: "error", data: error } })
},
async RestartInstance(host: string, SESSIONID: string, InstanceName: string) {
return axios.post(host + "/API/ADSModule/RestartInstance", { SESSIONID, InstanceName })
.then((response: AxiosResponse<APIResponse>) => {
//if (!response.data.success) return { status: "fail", data: response.data }
return { status: "success", data: response.data }
})
.catch((error: unknown) => { console.error(error); return { status: "error", data: error } })
},
async Servers(host: string, SESSIONID: string, InstanceId: string) {
return axios.get(host + "/API/ADSModule/Servers", { data: { SESSIONID, InstanceId } })
.then((response: AxiosResponse<APIResponse>) => {
if (!response.data.result) return { status: "fail", data: response.data }
return { status: "success", data: response.data }
})
.catch((error: unknown) => { console.error(error); return { status: "error", data: error } })
}
}
export const Core = {
async Login(host: string, details: LoginDetails) {
return axios.post(host + "/API/Core/Login", details)
.then((response: AxiosResponse<APIResponse>) => {
if (!response.data.success) return { status: "fail", data: response.data }
return { status: "success", data: response.data }
})
.catch((error: unknown) => { console.error(error); return { status: "error", data: error } })
}
}
export async function CheckSession(host: string, SESSIONID: string) {
return axios.post(host + "/API/ADSModule/GetInstances", { SESSIONID })
.then((response: AxiosResponse<APIResponse>) => {
if (!Array.isArray(response.data)) return { status: "fail", data: response.data }
return { status: "success", data: response.data }
})
.catch((error: unknown) => { console.error(error); return { status: "error", data: error } })
}