2022-05-07 22:18:14 +00:00
|
|
|
import useSWR, { ConfigInterface } from 'swr';
|
2020-08-26 04:25:31 +00:00
|
|
|
import http, { FractalResponseList } from '@/api/http';
|
|
|
|
import { rawDataToServerEggVariable } from '@/api/transformers';
|
|
|
|
import { ServerEggVariable } from '@/api/server/types';
|
|
|
|
|
|
|
|
interface Response {
|
|
|
|
invocation: string;
|
|
|
|
variables: ServerEggVariable[];
|
2022-05-07 21:45:22 +00:00
|
|
|
dockerImages: Record<string, string>;
|
2020-08-26 04:25:31 +00:00
|
|
|
}
|
|
|
|
|
2022-05-07 22:18:14 +00:00
|
|
|
export default (uuid: string, initialData?: Response | null, config?: ConfigInterface<Response>) => useSWR([ uuid, '/startup' ], async (): Promise<Response> => {
|
2020-08-26 04:25:31 +00:00
|
|
|
const { data } = await http.get(`/api/client/servers/${uuid}/startup`);
|
|
|
|
|
|
|
|
const variables = ((data as FractalResponseList).data || []).map(rawDataToServerEggVariable);
|
|
|
|
|
2022-05-07 21:45:22 +00:00
|
|
|
return {
|
|
|
|
variables,
|
|
|
|
invocation: data.meta.startup_command,
|
|
|
|
dockerImages: data.meta.docker_images || {},
|
|
|
|
};
|
2022-05-07 22:18:14 +00:00
|
|
|
}, { initialData: initialData || undefined, errorRetryCount: 3, ...(config || {}) });
|