add serverid from url

This commit is contained in:
2024-09-01 09:34:11 +00:00
parent 280f221141
commit 55d6d45051

View File

@@ -9,6 +9,7 @@ import ContextMenuContainer from "./ContextMenu/container";
import RenamePopup from "./ContextMenu/rename"; import RenamePopup from "./ContextMenu/rename";
import Pterodactyl from "@/components/Pterodactyl"; import Pterodactyl from "@/components/Pterodactyl";
import BreadCrumbs from "./BreadCrumbs"; import BreadCrumbs from "./BreadCrumbs";
import { useSearchParams } from "next/navigation";
interface FileAttributes { interface FileAttributes {
name: string; name: string;
@@ -54,8 +55,9 @@ const Index = () => {
); );
const [selectedFile, setSelectedFile] = useState<FileProps | null>(null); const [selectedFile, setSelectedFile] = useState<FileProps | null>(null);
const [ptero, setPtero] = useState<Pterodactyl | null>(null); const [ptero, setPtero] = useState<Pterodactyl | null>(null);
const [serverId, setServerId] = useState<string>("ec46691a"); const [path, setPath] = useState<string>("/");
const [path, setPath] = useState<string>("/world"); const urlParams = useSearchParams();
const serverId = urlParams.get("serverid");
const setCredentials = useCallback(() => { const setCredentials = useCallback(() => {
setApiKey("ptlc_N77A2hEczFmSwGXm4cEXh4Gw3ZP0Ygr5NaBkGlE7pjU"); setApiKey("ptlc_N77A2hEczFmSwGXm4cEXh4Gw3ZP0Ygr5NaBkGlE7pjU");
@@ -112,7 +114,7 @@ const Index = () => {
useEffect(() => { useEffect(() => {
const setupApplication = async () => { const setupApplication = async () => {
await setCredentials(); await setCredentials();
if (apiKey) { if (apiKey && serverId) {
const pteroInstance = new Pterodactyl(serverId, apiKey); const pteroInstance = new Pterodactyl(serverId, apiKey);
pteroInstance.helpers.setWorkingDirectory(path); pteroInstance.helpers.setWorkingDirectory(path);
setPtero(pteroInstance); setPtero(pteroInstance);
@@ -150,7 +152,8 @@ const Index = () => {
/> />
</div> </div>
{fileList.map((file: FileProps) => ( {serverId &&
fileList.map((file: FileProps) => (
<div <div
className="flex justify-between gap-4 bg-content mb-1 hover:bg-neutral-content pl-4 pr-4 pt-1 pb-1 rounded-md" className="flex justify-between gap-4 bg-content mb-1 hover:bg-neutral-content pl-4 pr-4 pt-1 pb-1 rounded-md"
key={file.attributes.name} key={file.attributes.name}
@@ -162,7 +165,10 @@ const Index = () => {
<div className="w-48 text-right"> <div className="w-48 text-right">
{file.attributes.is_file ? `${file.attributes.size} bytes` : ""} {file.attributes.is_file ? `${file.attributes.size} bytes` : ""}
</div> </div>
<div title={file.attributes.modified_at} className="w-60 text-right"> <div
title={file.attributes.modified_at}
className="w-60 text-right"
>
{formatDistanceToNow(new Date(file.attributes.modified_at), { {formatDistanceToNow(new Date(file.attributes.modified_at), {
addSuffix: true, addSuffix: true,
})} })}