2024-03-11 13:22:33 -04:00
|
|
|
import http, { FractalResponseData, FractalResponseList } from '@/api/http';
|
|
|
|
import { rawDataToServerAllocation, rawDataToServerEggVariable } from '@/api/transformers';
|
|
|
|
import { ServerEggVariable, ServerStatus } from '@/api/server/types';
|
|
|
|
|
|
|
|
export interface Allocation {
|
2024-04-08 08:26:01 -04:00
|
|
|
id: number;
|
|
|
|
ip: string;
|
|
|
|
alias: string | null;
|
|
|
|
port: number;
|
|
|
|
notes: string | null;
|
|
|
|
isDefault: boolean;
|
2024-03-11 13:22:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Server {
|
2024-04-08 08:26:01 -04:00
|
|
|
id: string;
|
|
|
|
internalId: number | string;
|
|
|
|
uuid: string;
|
|
|
|
name: string;
|
|
|
|
node: string;
|
|
|
|
isNodeUnderMaintenance: boolean;
|
|
|
|
status: ServerStatus;
|
|
|
|
sftpDetails: {
|
|
|
|
ip: string;
|
|
|
|
port: number;
|
|
|
|
};
|
|
|
|
invocation: string;
|
|
|
|
dockerImage: string;
|
|
|
|
description: string;
|
|
|
|
limits: {
|
|
|
|
memory: number;
|
|
|
|
swap: number;
|
|
|
|
disk: number;
|
|
|
|
io: number;
|
|
|
|
cpu: number;
|
|
|
|
threads: string;
|
|
|
|
};
|
|
|
|
eggFeatures: string[];
|
|
|
|
featureLimits: {
|
|
|
|
databases: number;
|
|
|
|
allocations: number;
|
|
|
|
backups: number;
|
|
|
|
};
|
|
|
|
isTransferring: boolean;
|
|
|
|
variables: ServerEggVariable[];
|
|
|
|
allocations: Allocation[];
|
|
|
|
|
|
|
|
BlueprintFramework: {
|
|
|
|
eggId: number;
|
|
|
|
};
|
2024-03-11 13:22:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export const rawDataToServerObject = ({ attributes: data }: FractalResponseData): Server => ({
|
2024-04-08 08:26:01 -04:00
|
|
|
id: data.identifier,
|
|
|
|
internalId: data.internal_id,
|
|
|
|
uuid: data.uuid,
|
|
|
|
name: data.name,
|
|
|
|
node: data.node,
|
|
|
|
isNodeUnderMaintenance: data.is_node_under_maintenance,
|
|
|
|
status: data.status,
|
|
|
|
invocation: data.invocation,
|
|
|
|
dockerImage: data.docker_image,
|
|
|
|
sftpDetails: {
|
|
|
|
ip: data.sftp_details.ip,
|
|
|
|
port: data.sftp_details.port,
|
|
|
|
},
|
|
|
|
description: data.description ? (data.description.length > 0 ? data.description : null) : null,
|
|
|
|
limits: { ...data.limits },
|
|
|
|
eggFeatures: data.egg_features || [],
|
|
|
|
featureLimits: { ...data.feature_limits },
|
|
|
|
isTransferring: data.is_transferring,
|
|
|
|
variables: ((data.relationships?.variables as FractalResponseList | undefined)?.data || []).map(
|
|
|
|
rawDataToServerEggVariable
|
|
|
|
),
|
|
|
|
allocations: ((data.relationships?.allocations as FractalResponseList | undefined)?.data || []).map(
|
|
|
|
rawDataToServerAllocation
|
|
|
|
),
|
2024-03-11 13:22:33 -04:00
|
|
|
|
2024-04-08 08:26:01 -04:00
|
|
|
BlueprintFramework: {
|
|
|
|
eggId: data.BlueprintFramework.egg_id,
|
|
|
|
},
|
2024-03-11 13:22:33 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default (uuid: string): Promise<[Server, string[]]> => {
|
2024-04-08 08:26:01 -04:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
http
|
|
|
|
.get(`/api/client/servers/${uuid}`)
|
|
|
|
.then(({ data }) =>
|
|
|
|
resolve([
|
|
|
|
rawDataToServerObject(data),
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
data.meta?.is_server_owner ? ['*'] : data.meta?.user_permissions || [],
|
|
|
|
])
|
|
|
|
)
|
|
|
|
.catch(reject);
|
|
|
|
});
|
2024-07-26 11:54:54 -04:00
|
|
|
};
|