Réécriture complète 4.0
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 6m16s
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 6m16s
This commit is contained in:
116
src/utils/amp.ts
116
src/utils/amp.ts
@@ -1,89 +1,57 @@
|
||||
import axios from 'axios'
|
||||
|
||||
export interface LoginDetails {
|
||||
username: string
|
||||
password: string
|
||||
remember?: boolean
|
||||
otp?: string
|
||||
}
|
||||
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 await axios.post(host + '/API/ADSModule/GetInstances', {
|
||||
SESSIONID
|
||||
}).then(response => {
|
||||
if (!Array.isArray(response.data)) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
return { status: 'error', data: error }
|
||||
})
|
||||
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 await axios.post(host + '/API/ADSModule/ManageInstance', {
|
||||
SESSIONID,
|
||||
InstanceId
|
||||
}).then(response => {
|
||||
if (!response.data.result) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
return { status: 'error', data: error }
|
||||
})
|
||||
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 await axios.post(host + '/API/ADSModule/RestartInstance', {
|
||||
SESSIONID,
|
||||
InstanceName
|
||||
}).then(response => {
|
||||
//if (!response.data.success) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
return { status: 'error', data: error }
|
||||
})
|
||||
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 await axios.get(host + '/API/ADSModule/Servers', {
|
||||
data: {
|
||||
SESSIONID,
|
||||
InstanceId
|
||||
}
|
||||
}).then(response => {
|
||||
if (!response.data.result) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
return { status: 'error', data: error }
|
||||
})
|
||||
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 await axios.post(host + '/API/Core/Login',
|
||||
details
|
||||
).then(response => {
|
||||
if (!response.data.success) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
return { status: 'error', data: error }
|
||||
})
|
||||
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 await axios.post(host + '/API/ADSModule/GetInstances', {
|
||||
SESSIONID
|
||||
}).then(response => {
|
||||
if (!Array.isArray(response.data)) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
return { status: 'error', data: error }
|
||||
})
|
||||
}
|
||||
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 } })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user