misc_pterodactyl-panel/resources/scripts/api/swr/getServerAllocations.ts

16 lines
630 B
TypeScript
Raw Normal View History

import { ServerContext } from '@/state/server';
import useSWR from 'swr';
import http from '@/api/http';
import { rawDataToServerAllocation } from '@/api/transformers';
import { Allocation } from '@/api/server/getServer';
2020-11-01 05:30:03 +00:00
export default () => {
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
return useSWR<Allocation[]>([ 'server:allocations', uuid ], async () => {
const { data } = await http.get(`/api/client/servers/${uuid}/network/allocations`);
return (data.data || []).map(rawDataToServerAllocation);
2020-11-01 05:30:03 +00:00
}, { revalidateOnFocus: false, revalidateOnMount: false });
};