2020-07-10 02:56:46 +00:00
|
|
|
import http, { FractalResponseData, FractalResponseList } from '@/api/http';
|
2020-08-23 01:13:59 +00:00
|
|
|
import { rawDataToServerAllocation, rawDataToServerEggVariable } from '@/api/transformers';
|
2021-01-18 00:13:49 +00:00
|
|
|
import { ServerEggVariable, ServerStatus } from '@/api/server/types';
|
2019-06-29 23:14:32 +00:00
|
|
|
|
|
|
|
export interface Allocation {
|
2020-07-10 03:36:08 +00:00
|
|
|
id: number;
|
2019-06-29 23:14:32 +00:00
|
|
|
ip: string;
|
|
|
|
alias: string | null;
|
|
|
|
port: number;
|
2020-07-10 03:36:08 +00:00
|
|
|
notes: string | null;
|
2020-07-09 04:42:37 +00:00
|
|
|
isDefault: boolean;
|
2019-06-29 23:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Server {
|
|
|
|
id: string;
|
2020-11-08 21:18:15 +00:00
|
|
|
internalId: number | string;
|
2019-06-29 23:14:32 +00:00
|
|
|
uuid: string;
|
|
|
|
name: string;
|
|
|
|
node: string;
|
2021-01-18 00:13:49 +00:00
|
|
|
status: ServerStatus;
|
2019-12-07 23:58:37 +00:00
|
|
|
sftpDetails: {
|
|
|
|
ip: string;
|
|
|
|
port: number;
|
|
|
|
};
|
2020-08-22 22:43:28 +00:00
|
|
|
invocation: string;
|
2020-12-13 19:07:29 +00:00
|
|
|
dockerImage: string;
|
2019-06-29 23:14:32 +00:00
|
|
|
description: string;
|
|
|
|
limits: {
|
|
|
|
memory: number;
|
|
|
|
swap: number;
|
|
|
|
disk: number;
|
|
|
|
io: number;
|
|
|
|
cpu: number;
|
2020-03-29 21:12:35 +00:00
|
|
|
threads: string;
|
2019-06-29 23:14:32 +00:00
|
|
|
};
|
2020-11-03 04:52:41 +00:00
|
|
|
eggFeatures: string[];
|
2019-06-29 23:14:32 +00:00
|
|
|
featureLimits: {
|
|
|
|
databases: number;
|
|
|
|
allocations: number;
|
2020-04-26 19:12:29 +00:00
|
|
|
backups: number;
|
2019-06-29 23:14:32 +00:00
|
|
|
};
|
2020-04-26 00:58:09 +00:00
|
|
|
isInstalling: boolean;
|
2020-12-16 16:34:47 +00:00
|
|
|
isTransferring: boolean;
|
2020-08-23 01:13:59 +00:00
|
|
|
variables: ServerEggVariable[];
|
|
|
|
allocations: Allocation[];
|
2019-06-29 23:14:32 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 02:56:46 +00:00
|
|
|
export const rawDataToServerObject = ({ attributes: data }: FractalResponseData): Server => ({
|
2019-06-29 23:14:32 +00:00
|
|
|
id: data.identifier,
|
2020-11-02 05:14:02 +00:00
|
|
|
internalId: data.internal_id,
|
2019-06-29 23:14:32 +00:00
|
|
|
uuid: data.uuid,
|
|
|
|
name: data.name,
|
|
|
|
node: data.node,
|
2021-01-18 00:13:49 +00:00
|
|
|
status: data.status,
|
2020-08-22 22:43:28 +00:00
|
|
|
invocation: data.invocation,
|
2020-12-13 19:07:29 +00:00
|
|
|
dockerImage: data.docker_image,
|
2019-12-07 23:58:37 +00:00
|
|
|
sftpDetails: {
|
|
|
|
ip: data.sftp_details.ip,
|
|
|
|
port: data.sftp_details.port,
|
|
|
|
},
|
2022-06-26 19:13:52 +00:00
|
|
|
description: data.description ? (data.description.length > 0 ? data.description : null) : null,
|
2019-06-29 23:14:32 +00:00
|
|
|
limits: { ...data.limits },
|
2020-11-03 04:52:41 +00:00
|
|
|
eggFeatures: data.egg_features || [],
|
2019-06-29 23:14:32 +00:00
|
|
|
featureLimits: { ...data.feature_limits },
|
2021-01-18 00:13:49 +00:00
|
|
|
isInstalling: data.status === 'installing' || data.status === 'install_failed',
|
2020-12-16 16:34:47 +00:00
|
|
|
isTransferring: data.is_transferring,
|
2022-06-26 19:13:52 +00:00
|
|
|
variables: ((data.relationships?.variables as FractalResponseList | undefined)?.data || []).map(
|
|
|
|
rawDataToServerEggVariable
|
|
|
|
),
|
|
|
|
allocations: ((data.relationships?.allocations as FractalResponseList | undefined)?.data || []).map(
|
|
|
|
rawDataToServerAllocation
|
|
|
|
),
|
2019-06-29 23:14:32 +00:00
|
|
|
});
|
|
|
|
|
2022-06-26 19:13:52 +00:00
|
|
|
export default (uuid: string): Promise<[Server, string[]]> => {
|
2019-06-29 23:14:32 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
http.get(`/api/client/servers/${uuid}`)
|
2022-06-26 19:13:52 +00:00
|
|
|
.then(({ data }) =>
|
|
|
|
resolve([
|
|
|
|
rawDataToServerObject(data),
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
data.meta?.is_server_owner ? ['*'] : data.meta?.user_permissions || [],
|
|
|
|
])
|
|
|
|
)
|
2019-06-29 23:14:32 +00:00
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|