2022-12-11 06:49:10 +00:00
|
|
|
export async function requestTicket (username, password) {
|
|
|
|
let prms = new URLSearchParams({username: `${username}@pve`, password: password});
|
2022-12-13 00:00:11 +00:00
|
|
|
|
|
|
|
let content = {
|
2022-12-11 06:49:10 +00:00
|
|
|
method: "POST",
|
|
|
|
mode: "cors",
|
|
|
|
credentials: "include",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
|
|
},
|
|
|
|
body: prms.toString()
|
2022-12-13 00:00:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let response = await fetch("https://pve.tronnet.net/api2/json/access/ticket", content)
|
2022-12-12 23:56:57 +00:00
|
|
|
.then((response) => {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error('Network response was not OK');
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('There has been a problem with your fetch operation:', error);
|
2022-12-11 06:49:10 +00:00
|
|
|
});
|
2022-12-13 00:00:11 +00:00
|
|
|
|
2022-12-11 06:49:10 +00:00
|
|
|
let data = await response.json();
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setTicket (ticket) {
|
|
|
|
let d = new Date();
|
|
|
|
d.setTime(d.getTime() + (2*60*60*1000));
|
|
|
|
document.cookie = `PVEAuthCookie=${ticket}; path=/; expires=${d.toUTCString()}; domain=.tronnet.net`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function request (path, method, body) {
|
|
|
|
let prms = new URLSearchParams(body);
|
2022-12-13 00:00:11 +00:00
|
|
|
|
|
|
|
let content = {
|
2022-12-11 06:49:10 +00:00
|
|
|
method: method,
|
|
|
|
mode: "cors",
|
|
|
|
credentials: "include",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
|
|
"Cookie": document.cookie
|
|
|
|
}
|
2022-12-13 00:00:11 +00:00
|
|
|
}
|
2022-12-11 06:49:10 +00:00
|
|
|
if(method == "POST") {
|
2022-12-13 00:00:11 +00:00
|
|
|
content.body = prms.toString();
|
2022-12-11 06:49:10 +00:00
|
|
|
}
|
2022-12-13 00:00:11 +00:00
|
|
|
|
|
|
|
let response = await fetch(`https://pve.tronnet.net/api2/json${path}`, content)
|
|
|
|
.then((response) => {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error('Network response was not OK');
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('There has been a problem with your fetch operation:', error);
|
|
|
|
});
|
|
|
|
|
2022-12-11 06:49:10 +00:00
|
|
|
let data = await response.json();
|
|
|
|
return data;
|
|
|
|
}
|