2020-07-09 19:56:46 -07:00
|
|
|
import http, { FractalResponseData, FractalResponseList } from '@/api/http';
|
2020-08-22 18:13:59 -07:00
|
|
|
import { rawDataToServerAllocation, rawDataToServerEggVariable } from '@/api/transformers';
|
2021-01-17 16:13:49 -08:00
|
|
|
import { ServerEggVariable, ServerStatus } from '@/api/server/types';
|
2026-02-14 11:21:57 -08:00
|
|
|
import { Identifier } from '@/api/definitions';
|
2019-06-29 16:14:32 -07:00
|
|
|
|
|
|
|
|
export interface Allocation {
|
2020-07-09 20:36:08 -07:00
|
|
|
id: number;
|
2019-06-29 16:14:32 -07:00
|
|
|
ip: string;
|
|
|
|
|
alias: string | null;
|
|
|
|
|
port: number;
|
2020-07-09 20:36:08 -07:00
|
|
|
notes: string | null;
|
2020-07-08 21:42:37 -07:00
|
|
|
isDefault: boolean;
|
2019-06-29 16:14:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface Server {
|
2026-02-14 11:21:57 -08:00
|
|
|
/**
|
|
|
|
|
* This value is determined by the presence of the `PTERODACTYL_USE_SERVER_IDENTIFIERS` environment
|
|
|
|
|
* variable which changes what the API can respond with. It will eventually be removed and referenced
|
|
|
|
|
* as the "identifier" key, but this allows users to slowly opt-in to these new URLs and trial it
|
|
|
|
|
* as they wish.
|
|
|
|
|
*
|
|
|
|
|
* @deprecated this is the "uuid_short" which will be removed in 2.0, prefer use of "identifier"
|
|
|
|
|
*/
|
|
|
|
|
id: string | Identifier<'serv'>;
|
|
|
|
|
identifier: Identifier<'serv'>; // Set from "server_identifier" and should be used moving forward to reference a server.
|
2020-11-08 13:18:15 -08:00
|
|
|
internalId: number | string;
|
2026-02-14 11:21:57 -08:00
|
|
|
/**
|
|
|
|
|
* Exists only to maintain support in cases where the short-uuid is necessary for server reference
|
|
|
|
|
* and cannot be easily replaced with "identifier".
|
|
|
|
|
*
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
__deprecatedUuidShort: string;
|
2019-06-29 16:14:32 -07:00
|
|
|
uuid: string;
|
|
|
|
|
name: string;
|
|
|
|
|
node: string;
|
2022-11-07 00:02:30 +01:00
|
|
|
isNodeUnderMaintenance: boolean;
|
2021-01-17 16:13:49 -08:00
|
|
|
status: ServerStatus;
|
2019-12-07 15:58:37 -08:00
|
|
|
sftpDetails: {
|
|
|
|
|
ip: string;
|
|
|
|
|
port: number;
|
|
|
|
|
};
|
2020-08-22 15:43:28 -07:00
|
|
|
invocation: string;
|
2020-12-13 11:07:29 -08:00
|
|
|
dockerImage: string;
|
2019-06-29 16:14:32 -07:00
|
|
|
description: string;
|
|
|
|
|
limits: {
|
|
|
|
|
memory: number;
|
|
|
|
|
swap: number;
|
|
|
|
|
disk: number;
|
|
|
|
|
io: number;
|
|
|
|
|
cpu: number;
|
2020-03-29 17:12:35 -04:00
|
|
|
threads: string;
|
2019-06-29 16:14:32 -07:00
|
|
|
};
|
2020-11-02 20:52:41 -08:00
|
|
|
eggFeatures: string[];
|
2019-06-29 16:14:32 -07:00
|
|
|
featureLimits: {
|
|
|
|
|
databases: number;
|
|
|
|
|
allocations: number;
|
2020-04-26 12:12:29 -07:00
|
|
|
backups: number;
|
2019-06-29 16:14:32 -07:00
|
|
|
};
|
2020-12-16 09:34:47 -07:00
|
|
|
isTransferring: boolean;
|
2026-08-10 16:39:22 +01:00
|
|
|
skipScripts: boolean;
|
2020-08-22 18:13:59 -07:00
|
|
|
variables: ServerEggVariable[];
|
|
|
|
|
allocations: Allocation[];
|
2019-06-29 16:14:32 -07:00
|
|
|
}
|
|
|
|
|
|
2020-07-09 19:56:46 -07:00
|
|
|
export const rawDataToServerObject = ({ attributes: data }: FractalResponseData): Server => ({
|
2019-06-29 16:14:32 -07:00
|
|
|
id: data.identifier,
|
2026-02-14 11:21:57 -08:00
|
|
|
identifier: data.server_identifier,
|
2020-11-02 00:14:02 -05:00
|
|
|
internalId: data.internal_id,
|
2026-02-14 11:21:57 -08:00
|
|
|
__deprecatedUuidShort: data.__deprecated_uuid_short,
|
2019-06-29 16:14:32 -07:00
|
|
|
uuid: data.uuid,
|
|
|
|
|
name: data.name,
|
|
|
|
|
node: data.node,
|
2022-11-07 00:02:30 +01:00
|
|
|
isNodeUnderMaintenance: data.is_node_under_maintenance,
|
2021-01-17 16:13:49 -08:00
|
|
|
status: data.status,
|
2020-08-22 15:43:28 -07:00
|
|
|
invocation: data.invocation,
|
2020-12-13 11:07:29 -08:00
|
|
|
dockerImage: data.docker_image,
|
2019-12-07 15:58:37 -08:00
|
|
|
sftpDetails: {
|
|
|
|
|
ip: data.sftp_details.ip,
|
|
|
|
|
port: data.sftp_details.port,
|
|
|
|
|
},
|
2022-06-26 15:13:52 -04:00
|
|
|
description: data.description ? (data.description.length > 0 ? data.description : null) : null,
|
2019-06-29 16:14:32 -07:00
|
|
|
limits: { ...data.limits },
|
2020-11-02 20:52:41 -08:00
|
|
|
eggFeatures: data.egg_features || [],
|
2019-06-29 16:14:32 -07:00
|
|
|
featureLimits: { ...data.feature_limits },
|
2020-12-16 09:34:47 -07:00
|
|
|
isTransferring: data.is_transferring,
|
2026-08-10 16:39:22 +01:00
|
|
|
skipScripts: data.skip_scripts,
|
2022-06-26 15:13:52 -04:00
|
|
|
variables: ((data.relationships?.variables as FractalResponseList | undefined)?.data || []).map(
|
|
|
|
|
rawDataToServerEggVariable
|
|
|
|
|
),
|
|
|
|
|
allocations: ((data.relationships?.allocations as FractalResponseList | undefined)?.data || []).map(
|
|
|
|
|
rawDataToServerAllocation
|
|
|
|
|
),
|
2019-06-29 16:14:32 -07:00
|
|
|
});
|
|
|
|
|
|
2022-06-26 15:13:52 -04:00
|
|
|
export default (uuid: string): Promise<[Server, string[]]> => {
|
2019-06-29 16:14:32 -07:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
http.get(`/api/client/servers/${uuid}`)
|
2022-06-26 15:13:52 -04:00
|
|
|
.then(({ data }) =>
|
|
|
|
|
resolve([
|
|
|
|
|
rawDataToServerObject(data),
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
|
data.meta?.is_server_owner ? ['*'] : data.meta?.user_permissions || [],
|
|
|
|
|
])
|
|
|
|
|
)
|
2019-06-29 16:14:32 -07:00
|
|
|
.catch(reject);
|
|
|
|
|
});
|
|
|
|
|
};
|