refactor(gui): refactor gui to use RemoteClient trait and RemoteManagement component (#1489)

* refactor(gui): refactor gui to use RemoteClient trait and RemoteManagement component
* feat(gui): Add network config saving and refactor RemoteManagement
This commit is contained in:
Mg Pig
2025-10-20 22:07:01 +08:00
committed by GitHub
parent 67ac9b00ff
commit eba9504fc2
27 changed files with 1040 additions and 793 deletions
+44
View File
@@ -0,0 +1,44 @@
import { type Api, type NetworkTypes } from "easytier-frontend-lib";
import * as backend from "~/composables/backend";
export class GUIRemoteClient implements Api.RemoteClient {
async validate_config(config: NetworkTypes.NetworkConfig): Promise<Api.ValidateConfigResponse> {
return backend.validateConfig(config);
}
async run_network(config: NetworkTypes.NetworkConfig): Promise<undefined> {
await backend.runNetworkInstance(config);
}
async get_network_info(inst_id: string): Promise<NetworkTypes.NetworkInstanceRunningInfo | undefined> {
return backend.collectNetworkInfo(inst_id).then(infos => infos.info.map[inst_id]);
}
async list_network_instance_ids(): Promise<Api.ListNetworkInstanceIdResponse> {
return backend.listNetworkInstanceIds();
}
async delete_network(inst_id: string): Promise<undefined> {
await backend.deleteNetworkInstance(inst_id);
}
async update_network_instance_state(inst_id: string, disabled: boolean): Promise<undefined> {
await backend.updateNetworkConfigState(inst_id, disabled);
}
async save_config(config: NetworkTypes.NetworkConfig): Promise<undefined> {
await backend.saveNetworkConfig(config);
}
async get_network_config(inst_id: string): Promise<NetworkTypes.NetworkConfig> {
return backend.getConfig(inst_id);
}
async generate_config(config: NetworkTypes.NetworkConfig): Promise<Api.GenerateConfigResponse> {
try {
return { toml_config: await backend.parseNetworkConfig(config) };
} catch (e) {
return { error: e + "" };
}
}
async parse_config(toml_config: string): Promise<Api.ParseConfigResponse> {
try {
return { config: await backend.generateNetworkConfig(toml_config) }
} catch (e) {
return { error: e + "" };
}
}
}