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

31 lines
1 KiB
TypeScript
Raw Normal View History

2022-11-25 20:25:03 +00:00
import type { AxiosError } from 'axios';
import type { SWRConfiguration } from 'swr';
import useSWR from 'swr';
import http, { FractalResponseList } from '@/api/http';
2022-11-25 20:25:03 +00:00
import type { ServerEggVariable } from '@/api/server/types';
import { rawDataToServerEggVariable } from '@/api/transformers';
interface Response {
invocation: string;
variables: ServerEggVariable[];
dockerImages: Record<string, string>;
}
2022-11-25 20:25:03 +00:00
export default (uuid: string, fallbackData?: Response, config?: SWRConfiguration<Response, AxiosError>) =>
useSWR(
[uuid, '/startup'],
async (): Promise<Response> => {
const { data } = await http.get(`/api/client/servers/${uuid}/startup`);
const variables = ((data as FractalResponseList).data || []).map(rawDataToServerEggVariable);
return {
variables,
invocation: data.meta.startup_command,
dockerImages: data.meta.docker_images || {},
};
},
2022-11-25 20:25:03 +00:00
{ fallbackData, errorRetryCount: 3, ...(config ?? {}) },
);