feat(instance): add getInstanceInfo endpoint and refactor instance loading
- Add new getInstanceInfo API endpoint to fetch complete instance details - Refactor instance loading logic to use single API call instead of multiple - Update Instances.vue and InstanceDetail.vue to use new endpoint - Remove redundant status/config loading functions
This commit is contained in:
@@ -82,6 +82,8 @@ export const instanceApi = {
|
||||
api.post('/frpcAct/instanceMgr/stop', { instanceID }),
|
||||
restartInstance: (instanceID) =>
|
||||
api.post('/frpcAct/instanceMgr/restart', { instanceID }),
|
||||
getInstanceInfo: (instanceID) =>
|
||||
api.get(`/frpcAct/instanceMgr/getInfo?instanceID=${instanceID}`),
|
||||
getInstanceStatus: (instanceID) =>
|
||||
api.get(`/frpcAct/instanceMgr/status?instanceID=${instanceID}`),
|
||||
getInstanceLogs: (instanceID) =>
|
||||
|
||||
@@ -307,34 +307,27 @@ export default {
|
||||
runUser: ''
|
||||
});
|
||||
|
||||
const loadInstanceConfig = async () => {
|
||||
const loadInstanceInfo = async () => {
|
||||
try {
|
||||
const result = await instanceApi.listInstances();
|
||||
const instance = result.data.find(i => String(i.instanceID) === instanceID.value);
|
||||
if (instance) {
|
||||
instanceName.value = instance.name;
|
||||
instanceConfig.value = {
|
||||
'Server Address': instance.serverAddr,
|
||||
'Server Port': instance.serverPort,
|
||||
'Auth Method': instance.auth_method,
|
||||
'Boot At Start': instance.bootAtStart ? 'Yes' : 'No',
|
||||
'Run User': instance.runUser,
|
||||
'Config Path': instance.configPath,
|
||||
'Created At': formatDate(instance.createdAt)
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
showNotification('Load instance configuration failed', 'error');
|
||||
}
|
||||
};
|
||||
|
||||
const loadInstanceStatus = async () => {
|
||||
try {
|
||||
const result = await instanceApi.getInstanceStatus(instanceID.value);
|
||||
const result = await instanceApi.getInstanceInfo(instanceID.value);
|
||||
instanceName.value = result.data.name;
|
||||
instanceStatus.value = result.data.isRunning ? 'running' : 'stopped';
|
||||
statusInfo.value = result.data;
|
||||
statusInfo.value = {
|
||||
pid: result.data.pid,
|
||||
serviceName: result.data.serviceName,
|
||||
isRunning: result.data.isRunning
|
||||
};
|
||||
instanceConfig.value = {
|
||||
'Server Address': result.data.serverAddr || '',
|
||||
'Server Port': result.data.serverPort || '',
|
||||
'Auth Method': result.data.auth_method,
|
||||
'Boot At Start': result.data.bootAtStart ? 'Yes' : 'No',
|
||||
'Run User': result.data.runUser,
|
||||
'Config Path': result.data.configPath,
|
||||
'Created At': formatDate(result.data.createdAt)
|
||||
};
|
||||
} catch (error) {
|
||||
showNotification('Load instance status failed', 'error');
|
||||
showNotification('Load instance information failed', 'error');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -342,7 +335,7 @@ export default {
|
||||
try {
|
||||
await instanceApi.startInstance(instanceID.value);
|
||||
showNotification('Instance started successfully', 'success');
|
||||
await loadInstanceStatus();
|
||||
await loadInstanceInfo();
|
||||
} catch (error) {
|
||||
showNotification(error.message || 'Start instance failed', 'error');
|
||||
}
|
||||
@@ -352,7 +345,7 @@ export default {
|
||||
try {
|
||||
await instanceApi.stopInstance(instanceID.value);
|
||||
showNotification('Instance stopped successfully', 'success');
|
||||
await loadInstanceStatus();
|
||||
await loadInstanceInfo();
|
||||
} catch (error) {
|
||||
showNotification(error.message || 'Stop instance failed', 'error');
|
||||
}
|
||||
@@ -372,7 +365,7 @@ export default {
|
||||
try {
|
||||
await instanceApi.restartInstance(instanceID.value);
|
||||
showNotification('Instance restarted successfully', 'success');
|
||||
await loadInstanceStatus();
|
||||
await loadInstanceInfo();
|
||||
} catch (error) {
|
||||
showNotification(error.message || 'Restart instance failed', 'error');
|
||||
}
|
||||
@@ -421,24 +414,21 @@ export default {
|
||||
|
||||
const editConfig = async () => {
|
||||
try {
|
||||
const result = await instanceApi.listInstances();
|
||||
const instance = result.data.find(i => String(i.instanceID) === instanceID.value);
|
||||
if (instance) {
|
||||
instanceName.value = instance.name;
|
||||
formData.value = {
|
||||
name: instance.name,
|
||||
auth_method: instance.auth_method || 'token',
|
||||
serverAddr: instance.serverAddr || '',
|
||||
serverPort: instance.serverPort || '',
|
||||
token: '',
|
||||
clientId: '',
|
||||
clientSecret: '',
|
||||
audience: '',
|
||||
tokenEndpoint: '',
|
||||
bootAtStart: instance.bootAtStart || false,
|
||||
runUser: instance.runUser || 'root'
|
||||
};
|
||||
}
|
||||
const result = await instanceApi.getInstanceInfo(instanceID.value);
|
||||
instanceName.value = result.data.name;
|
||||
formData.value = {
|
||||
name: result.data.name,
|
||||
auth_method: result.data.auth_method || 'token',
|
||||
serverAddr: result.data.serverAddr || '',
|
||||
serverPort: result.data.serverPort || '',
|
||||
token: '',
|
||||
clientId: '',
|
||||
clientSecret: '',
|
||||
audience: '',
|
||||
tokenEndpoint: '',
|
||||
bootAtStart: result.data.bootAtStart || false,
|
||||
runUser: result.data.runUser || 'root'
|
||||
};
|
||||
} catch (error) {
|
||||
showNotification('Load instance data failed', 'error');
|
||||
return;
|
||||
@@ -497,8 +487,7 @@ export default {
|
||||
showNotification('Configuration saved successfully', 'success');
|
||||
closeEditConfigModal();
|
||||
closeAddProxyModal();
|
||||
// 重新加载配置
|
||||
await loadInstanceConfig();
|
||||
await loadInstanceInfo();
|
||||
} catch (error) {
|
||||
showNotification(error.message || 'Save configuration failed', 'error');
|
||||
} finally {
|
||||
@@ -530,8 +519,7 @@ export default {
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
await loadInstanceConfig();
|
||||
await loadInstanceStatus();
|
||||
await loadInstanceInfo();
|
||||
await loadProxies();
|
||||
await loadLogs();
|
||||
});
|
||||
|
||||
@@ -203,20 +203,30 @@ export default {
|
||||
|
||||
const loadInstances = async () => {
|
||||
try {
|
||||
const result = await instanceApi.listInstances();
|
||||
instances.value = result.data.map(instance => ({
|
||||
...instance,
|
||||
status: 'stopped'
|
||||
const listResult = await instanceApi.listInstances();
|
||||
const instanceIDs = listResult.data.map(i => String(i.instanceID));
|
||||
|
||||
const infoResults = await Promise.all(instanceIDs.map(async (instanceID) => {
|
||||
try {
|
||||
return await instanceApi.getInstanceInfo(instanceID);
|
||||
} catch (error) {
|
||||
console.error(`Failed to get info for instance ${instanceID}:`, error);
|
||||
return null;
|
||||
}
|
||||
}));
|
||||
|
||||
for (const instance of instances.value) {
|
||||
try {
|
||||
const statusResult = await instanceApi.getInstanceStatus(String(instance.instanceID));
|
||||
instance.status = statusResult.data.isRunning ? 'running' : 'stopped';
|
||||
} catch (error) {
|
||||
console.error(`Failed to load status for instance ${instance.instanceID}:`, error);
|
||||
instances.value = listResult.data.map(instance => {
|
||||
const infoResult = infoResults.find(r => r && String(r.data.instanceID) === String(instance.instanceID));
|
||||
if (infoResult) {
|
||||
return {
|
||||
...instance,
|
||||
status: infoResult.data.isRunning ? 'running' : 'stopped',
|
||||
serviceName: infoResult.data.serviceName,
|
||||
pid: infoResult.data.pid
|
||||
};
|
||||
}
|
||||
}
|
||||
return { ...instance, status: 'stopped' };
|
||||
});
|
||||
} catch (error) {
|
||||
showNotification('Load instance list failed', 'error');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user