add serverid from url
This commit is contained in:
@@ -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,28 +152,32 @@ const Index = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{fileList.map((file: FileProps) => (
|
{serverId &&
|
||||||
<div
|
fileList.map((file: FileProps) => (
|
||||||
className="flex justify-between gap-4 bg-content mb-1 hover:bg-neutral-content pl-4 pr-4 pt-1 pb-1 rounded-md"
|
<div
|
||||||
key={file.attributes.name}
|
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 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>
|
||||||
<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>
|
|
||||||
))}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user