Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/api/swr/getServerAllocations.ts
7461 views
1
import { ServerContext } from '@/state/server';
2
import useSWR from 'swr';
3
import http from '@/api/http';
4
import { rawDataToServerAllocation } from '@/api/transformers';
5
import { Allocation } from '@/api/server/getServer';
6
7
export default () => {
8
const uuid = ServerContext.useStoreState((state) => state.server.data!.uuid);
9
10
return useSWR<Allocation[]>(
11
['server:allocations', uuid],
12
async () => {
13
const { data } = await http.get(`/api/client/servers/${uuid}/network/allocations`);
14
15
return (data.data || []).map(rawDataToServerAllocation);
16
},
17
{ revalidateOnFocus: false, revalidateOnMount: false }
18
);
19
};
20
21