Files
pterodactyl-panel/resources/scripts/api/server/getServer.ts
T
SkyMulley 850f2b9a4f Disable reinstall action during normal server status if "skip egg install scripts" setting is enabled (#5696)
### Description

You're able to enable a "skip egg install scripts" per server, while
still being able to reinstall a server. With this setting enabled,
reinstalling a server has no functional use, the server is locked and
shutdown, then simply unlocked immediately afterwards after a success
signal from wings. This PR disables the reinstall button when skip
install scripts is enabled for both the user and admin, with a little
component telling you why you cannot reinstall. The reinstall button is
not disabled if the server is in a status that reinstall could resolve
(eg. failed install).

### Resolved issues:
1. [x] resolves pterodactyl/panel#5306
2026-08-10 11:39:22 -04:00

109 lines
3.6 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;
skipScripts: 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,
skipScripts: data.skip_scripts,
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);
});
};