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