loading file into text editor

This commit is contained in:
2024-09-13 21:00:08 +00:00
parent 437701ffac
commit faa45f7fcf
6 changed files with 97 additions and 36 deletions

View File

@@ -1,3 +1,4 @@
import { get } from "http";
import { File } from "./interfaces";
export default function files(pterodactyl: any) {
@@ -57,5 +58,24 @@ export default function files(pterodactyl: any) {
console.error("Error fetching data:", error);
}
},
async getContent(filename: string) {
try {
const response = await fetch(
`${process.env.NEXT_PUBLIC_URL}/api/client/servers/${pterodactyl.server_id}/files/contents?file=${filename}`,
{
method: "GET",
headers: await pterodactyl.helpers.authHeader(),
}
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.text();
return data;
} catch (error) {
console.error("Error fetching data:", error);
}
},
};
}

View File

@@ -2,15 +2,21 @@ import filesModule from "./files";
import helpersModule from "./helpers";
class Pterodactyl {
server_id: string;
api_key: string;
server_id: string = "";
api_key: string = "";
files: any;
helpers: any;
workingDirectory: string = "/";
constructor(server_id: string, api_key: string) {
this.server_id = server_id;
setApiKey(api_key: string) {
this.api_key = api_key;
}
setServerId(server_id: string) {
this.server_id = server_id;
}
constructor() {
this.files = filesModule(this);
this.helpers = helpersModule(this);
}