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 Pterodactyl from "@/components/Pterodactyl";
import BreadCrumbs from "./BreadCrumbs";
import { useSearchParams } from "next/navigation";
interface FileAttributes {
name: string;
@@ -54,8 +55,9 @@ const Index = () => {
);
const [selectedFile, setSelectedFile] = useState<FileProps | null>(null);
const [ptero, setPtero] = useState<Pterodactyl | null>(null);
const [serverId, setServerId] = useState<string>("ec46691a");
const [path, setPath] = useState<string>("/world");
const [path, setPath] = useState<string>("/");
const urlParams = useSearchParams();
const serverId = urlParams.get("serverid");
const setCredentials = useCallback(() => {
setApiKey("ptlc_N77A2hEczFmSwGXm4cEXh4Gw3ZP0Ygr5NaBkGlE7pjU");
@@ -112,7 +114,7 @@ const Index = () => {
useEffect(() => {
const setupApplication = async () => {
await setCredentials();
if (apiKey) {
if (apiKey && serverId) {
const pteroInstance = new Pterodactyl(serverId, apiKey);
pteroInstance.helpers.setWorkingDirectory(path);
setPtero(pteroInstance);
@@ -150,28 +152,32 @@ const Index = () => {
/>
</div>
{fileList.map((file: FileProps) => (
<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"
key={file.attributes.name}
>
<div className="w-10">
{file.attributes.is_file ? <DocumentIcon /> : <FolderIcon />}
{serverId &&
fileList.map((file: FileProps) => (
<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"
key={file.attributes.name}
>
<div className="w-10">
{file.attributes.is_file ? <DocumentIcon /> : <FolderIcon />}
</div>
<div className="w-64 text-left">{file.attributes.name}</div>
<div className="w-48 text-right">
{file.attributes.is_file ? `${file.attributes.size} bytes` : ""}
</div>
<div
title={file.attributes.modified_at}
className="w-60 text-right"
>
{formatDistanceToNow(new Date(file.attributes.modified_at), {
addSuffix: true,
})}
</div>
<div onClick={(e) => handleClickContextMenu(e, file)}>
<MenuIcon />
</div>
</div>
<div className="w-64 text-left">{file.attributes.name}</div>
<div className="w-48 text-right">
{file.attributes.is_file ? `${file.attributes.size} bytes` : ""}
</div>
<div title={file.attributes.modified_at} className="w-60 text-right">
{formatDistanceToNow(new Date(file.attributes.modified_at), {
addSuffix: true,
})}
</div>
<div onClick={(e) => handleClickContextMenu(e, file)}>
<MenuIcon />
</div>
</div>
))}
))}
</>
);
};