57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { File } from "./interfaces";
|
|
|
|
export default function files(pterodactyl: any) {
|
|
return {
|
|
async rename(from: File, newName: string) {
|
|
console.log("rename", from);
|
|
|
|
try {
|
|
const response = await fetch(
|
|
`${process.env.NEXT_PUBLIC_URL}/api/client/servers/${pterodactyl.server_id}/files/rename`,
|
|
{
|
|
method: "PUT",
|
|
headers: await pterodactyl.helpers.authHeader(),
|
|
body: JSON.stringify({
|
|
root: "/",
|
|
files: [
|
|
{
|
|
from: from.attributes.name,
|
|
to: newName,
|
|
},
|
|
],
|
|
}),
|
|
}
|
|
);
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
console.log(response);
|
|
if (response.ok) {
|
|
// fetchFiles();
|
|
}
|
|
} catch (error) {
|
|
console.error("Error fetching data:", error);
|
|
}
|
|
},
|
|
|
|
async fetchFiles() {
|
|
try {
|
|
const response = await fetch(
|
|
`${process.env.NEXT_PUBLIC_URL}/api/client/servers/${pterodactyl.server_id}/files/list`,
|
|
{
|
|
method: "GET",
|
|
headers: await pterodactyl.helpers.authHeader(),
|
|
}
|
|
);
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
const data = await response.json();
|
|
return data.data;
|
|
} catch (error) {
|
|
console.error("Error fetching data:", error);
|
|
}
|
|
},
|
|
};
|
|
}
|