misc_pterodactyl-panel/resources/scripts/plugins/useFileManagerSwr.ts

23 lines
817 B
TypeScript
Raw Normal View History

import useSWR from 'swr';
import loadDirectory, { FileObject } from '@/api/server/files/loadDirectory';
import { cleanDirectoryPath } from '@/helpers';
2020-07-18 17:45:41 +00:00
import { ServerContext } from '@/state/server';
export const getDirectorySwrKey = (uuid: string, directory: string): string => `${uuid}:files:${directory}`;
export default () => {
2022-11-25 20:25:03 +00:00
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
const directory = ServerContext.useStoreState(state => state.files.directory);
return useSWR<FileObject[]>(
getDirectorySwrKey(uuid, directory),
2020-07-18 17:45:41 +00:00
() => loadDirectory(uuid, cleanDirectoryPath(directory)),
2020-07-11 05:53:52 +00:00
{
focusThrottleInterval: 30000,
revalidateOnMount: false,
2020-07-11 05:53:52 +00:00
refreshInterval: 0,
errorRetryCount: 2,
2022-11-25 20:25:03 +00:00
},
);
};