This commit is contained in:
2024-10-15 21:37:55 +00:00
parent e677a45ecd
commit 7302b27dc3
10 changed files with 233 additions and 28 deletions

View File

@@ -1,10 +1,10 @@
export default function helpers(pterodactyl: any) {
return {
// helper what return auth header
async authHeader() {
async authHeader(contentType: string = "application/json") {
return {
Authorization: `Bearer ${pterodactyl.api_key}`,
"Content-Type": "application/json",
"Content-Type": contentType,
Accept: "Application/vnd.pterodactyl.v1+json",
};
},
@@ -28,5 +28,16 @@ export default function helpers(pterodactyl: any) {
async getWorkingDirectory() {
return pterodactyl.workingDirectory;
},
// helper that get main site and get csrf token from it
async getCsrfToken() {
const response = await fetch(`${process.env.NEXT_PUBLIC_URL}`, {
method: "GET",
});
const text = await response.text();
const match = text.match(/<meta name="csrf-token" content="(.*)">/);
const csrfToken = match ? match[1] : null;
return csrfToken;
},
};
}