feat: 完整游戏运维功能
This commit is contained in:
@@ -15,6 +15,14 @@ export interface ServerCreateFormState {
|
||||
name: string;
|
||||
pluginId: string;
|
||||
runEndpointId: string;
|
||||
profileKey: string;
|
||||
bindings: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface RuntimeBindingField {
|
||||
key: string;
|
||||
required: boolean;
|
||||
sensitive: boolean;
|
||||
}
|
||||
|
||||
export interface ServerWorkflowActionState {
|
||||
@@ -46,7 +54,9 @@ export const emptyServerCreateForm: ServerCreateFormState = {
|
||||
id: "",
|
||||
name: "",
|
||||
pluginId: "",
|
||||
runEndpointId: ""
|
||||
runEndpointId: "",
|
||||
profileKey: "",
|
||||
bindings: {}
|
||||
};
|
||||
|
||||
export function summarizeServerManagement(instances: ServerInstanceResponse[], jobs: JobResponse[]): ServerManagementSummary {
|
||||
@@ -85,17 +95,43 @@ export function canStopServer(state: ServerInstanceState): boolean {
|
||||
}
|
||||
|
||||
export function isPendingJobState(state: JobResponse["state"]): boolean {
|
||||
return state === "queued" || state === "accepted" || state === "running";
|
||||
return state === "queued" || state === "accepted" || state === "running" || state === "retrying";
|
||||
}
|
||||
|
||||
export function defaultServerCreateForm(plugins: GamePluginResponse[], endpoints: RunEndpointResponse[]): ServerCreateFormState {
|
||||
const plugin = plugins[0];
|
||||
return {
|
||||
...emptyServerCreateForm,
|
||||
pluginId: plugins[0]?.id ?? "",
|
||||
pluginId: plugin?.id ?? "",
|
||||
profileKey: plugin?.runtimeProfiles?.lifecycleProfiles?.[0]?.key ?? "",
|
||||
runEndpointId: endpoints[0]?.id ?? ""
|
||||
};
|
||||
}
|
||||
|
||||
export function runtimeBindingFields(plugin: GamePluginResponse | undefined, profileKey: string): RuntimeBindingField[] {
|
||||
const profiles = plugin?.runtimeProfiles;
|
||||
const lifecycle = profiles?.lifecycleProfiles?.find((profile) => profile.key === profileKey);
|
||||
if (!profiles || !lifecycle) return [];
|
||||
const fields = new Map<string, RuntimeBindingField>();
|
||||
const add = (key: string | undefined, required: boolean) => {
|
||||
if (!key) return;
|
||||
const current = fields.get(key);
|
||||
fields.set(key, { key, required: required || current?.required === true, sensitive: runtimeBindingKeyIsSensitive(key) });
|
||||
};
|
||||
profiles.discovery?.forEach((probe) => add(probe.targetKey, probe.required === true));
|
||||
profiles.dependencyProbes?.forEach((probe) => add(probe.targetKey, probe.required === true));
|
||||
profiles.logSources?.forEach((source) => add(source.targetKey, Boolean(source.targetKey)));
|
||||
profiles.installPlans?.forEach((plan) => plan.steps.forEach((step) => add(step.targetKey, false)));
|
||||
profiles.transportProfiles?.filter((transport) => lifecycle.transportKeys?.includes(transport.key)).forEach((transport) => add(transport.targetKey || transport.key, true));
|
||||
add(lifecycle.clientManagerRef, Boolean(lifecycle.clientManagerRef));
|
||||
return [...fields.values()].sort((left, right) => left.key.localeCompare(right.key));
|
||||
}
|
||||
|
||||
export function runtimeBindingKeyIsSensitive(key: string): boolean {
|
||||
const normalized = key.toLowerCase();
|
||||
return ["password", "credential", "secret", "token", "dsn"].some((part) => normalized.includes(part));
|
||||
}
|
||||
|
||||
export function serverMetadataFormFromInstance(instance: ServerInstanceResponse): ServerMetadataFormState {
|
||||
return { name: instance.name };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user