update
This commit is contained in:
@@ -77,5 +77,29 @@ export default function files(pterodactyl: any) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
},
|
||||
|
||||
async saveContent(filename: string, content: string) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_URL}/api/client/servers/${pterodactyl.server_id}/files/write?file=${filename}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: await pterodactyl.helpers.authHeader("application/text"),
|
||||
body: "'test'",
|
||||
}
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
},
|
||||
|
||||
async createFile(filename: string) {
|
||||
this.saveContent(filename, "");
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user