mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-29 10:55:43 -05:00
This is a partial implementation to begin moving towards stripe-style identifiers for resources in the system. Any models with an existing `uuid` column can easily be updated to return an identifier in the format of `prfx_xyz` where `prfx` is a four character prefix, and `xyz` is the UUID, encoded using base-32. These are quite easy to use within the API layer because we just need to do one quick transformation to extract the UUID for those models. This PR implements that logic for servers in the `SubstituteClientBindings` logic. A future PR will need to come through and handle identifiers for models that _don't_ currently use UUIDs for reference that we want to expose to clients. In those cases it is easier to just generate base-32 encoded UUID7s that get stored in the database and indexed. They follow the same base approach, but you don't need to do any transformations in the code (other than stripping the prefix, unless we decide to store the prefix). There is also now a `PTERODACTYL_USE_SERVER_IDENTIFIERS` environment variable, that when set to true, updates the front-end and API response to use this new identifier in place of the `uuidShort` value.
107 lines
3.5 KiB
TypeScript
107 lines
3.5 KiB
TypeScript
import http, { FractalResponseData, FractalResponseList } from '@/api/http';
|
|
import { rawDataToServerAllocation, rawDataToServerEggVariable } from '@/api/transformers';
|
|
import { ServerEggVariable, ServerStatus } from '@/api/server/types';
|
|
import { Identifier } from '@/api/definitions';
|
|
|
|
export interface Allocation {
|
|
id: number;
|
|
ip: string;
|
|
alias: string | null;
|
|
port: number;
|
|
notes: string | null;
|
|
isDefault: boolean;
|
|
}
|
|
|
|
export interface Server {
|
|
/**
|
|
* 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.
|
|
internalId: number | string;
|
|
/**
|
|
* 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;
|
|
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[];
|
|
}
|
|
|
|
export const rawDataToServerObject = ({ attributes: data }: FractalResponseData): Server => ({
|
|
id: data.identifier,
|
|
identifier: data.server_identifier,
|
|
internalId: data.internal_id,
|
|
__deprecatedUuidShort: data.__deprecated_uuid_short,
|
|
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
|
|
),
|
|
});
|
|
|
|
export default (uuid: string): Promise<[Server, string[]]> => {
|
|
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);
|
|
});
|
|
};
|