2020-08-26 04:25:31 +00:00
|
|
|
import useSWR from 'swr';
|
|
|
|
import http, { FractalResponseList } from '@/api/http';
|
2022-02-27 17:25:31 +00:00
|
|
|
import { Transformers, ServerEggVariable } from '@definitions/user';
|
2020-08-26 04:25:31 +00:00
|
|
|
|
|
|
|
interface Response {
|
|
|
|
invocation: string;
|
|
|
|
variables: ServerEggVariable[];
|
2020-12-13 19:07:29 +00:00
|
|
|
dockerImages: string[];
|
2020-08-26 04:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default (uuid: string, initialData?: Response) => useSWR([ uuid, '/startup' ], async (): Promise<Response> => {
|
|
|
|
const { data } = await http.get(`/api/client/servers/${uuid}/startup`);
|
|
|
|
|
2022-02-27 17:25:31 +00:00
|
|
|
const variables = ((data as FractalResponseList).data || []).map(Transformers.toServerEggVariable);
|
2020-08-26 04:25:31 +00:00
|
|
|
|
2020-12-13 19:07:29 +00:00
|
|
|
return { invocation: data.meta.startup_command, variables, dockerImages: data.meta.docker_images || [] };
|
2021-09-10 21:26:02 +00:00
|
|
|
}, { fallbackData: initialData, errorRetryCount: 3 });
|