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 }),
|
api.post('/frpcAct/instanceMgr/stop', { instanceID }),
|
||||||
restartInstance: (instanceID) =>
|
restartInstance: (instanceID) =>
|
||||||
api.post('/frpcAct/instanceMgr/restart', { instanceID }),
|
api.post('/frpcAct/instanceMgr/restart', { instanceID }),
|
||||||
|
getInstanceInfo: (instanceID) =>
|
||||||
|
api.get(`/frpcAct/instanceMgr/getInfo?instanceID=${instanceID}`),
|
||||||
getInstanceStatus: (instanceID) =>
|
getInstanceStatus: (instanceID) =>
|
||||||
api.get(`/frpcAct/instanceMgr/status?instanceID=${instanceID}`),
|
api.get(`/frpcAct/instanceMgr/status?instanceID=${instanceID}`),
|
||||||
getInstanceLogs: (instanceID) =>
|
getInstanceLogs: (instanceID) =>
|
||||||
|
|||||||
@@ -307,34 +307,27 @@ export default {
|
|||||||
runUser: ''
|
runUser: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
const loadInstanceConfig = async () => {
|
const loadInstanceInfo = async () => {
|
||||||
try {
|
try {
|
||||||
const result = await instanceApi.listInstances();
|
const result = await instanceApi.getInstanceInfo(instanceID.value);
|
||||||
const instance = result.data.find(i => String(i.instanceID) === instanceID.value);
|
instanceName.value = result.data.name;
|
||||||
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);
|
|
||||||
instanceStatus.value = result.data.isRunning ? 'running' : 'stopped';
|
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) {
|
} catch (error) {
|
||||||
showNotification('Load instance status failed', 'error');
|
showNotification('Load instance information failed', 'error');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -342,7 +335,7 @@ export default {
|
|||||||
try {
|
try {
|
||||||
await instanceApi.startInstance(instanceID.value);
|
await instanceApi.startInstance(instanceID.value);
|
||||||
showNotification('Instance started successfully', 'success');
|
showNotification('Instance started successfully', 'success');
|
||||||
await loadInstanceStatus();
|
await loadInstanceInfo();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNotification(error.message || 'Start instance failed', 'error');
|
showNotification(error.message || 'Start instance failed', 'error');
|
||||||
}
|
}
|
||||||
@@ -352,7 +345,7 @@ export default {
|
|||||||
try {
|
try {
|
||||||
await instanceApi.stopInstance(instanceID.value);
|
await instanceApi.stopInstance(instanceID.value);
|
||||||
showNotification('Instance stopped successfully', 'success');
|
showNotification('Instance stopped successfully', 'success');
|
||||||
await loadInstanceStatus();
|
await loadInstanceInfo();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNotification(error.message || 'Stop instance failed', 'error');
|
showNotification(error.message || 'Stop instance failed', 'error');
|
||||||
}
|
}
|
||||||
@@ -372,7 +365,7 @@ export default {
|
|||||||
try {
|
try {
|
||||||
await instanceApi.restartInstance(instanceID.value);
|
await instanceApi.restartInstance(instanceID.value);
|
||||||
showNotification('Instance restarted successfully', 'success');
|
showNotification('Instance restarted successfully', 'success');
|
||||||
await loadInstanceStatus();
|
await loadInstanceInfo();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNotification(error.message || 'Restart instance failed', 'error');
|
showNotification(error.message || 'Restart instance failed', 'error');
|
||||||
}
|
}
|
||||||
@@ -421,24 +414,21 @@ export default {
|
|||||||
|
|
||||||
const editConfig = async () => {
|
const editConfig = async () => {
|
||||||
try {
|
try {
|
||||||
const result = await instanceApi.listInstances();
|
const result = await instanceApi.getInstanceInfo(instanceID.value);
|
||||||
const instance = result.data.find(i => String(i.instanceID) === instanceID.value);
|
instanceName.value = result.data.name;
|
||||||
if (instance) {
|
formData.value = {
|
||||||
instanceName.value = instance.name;
|
name: result.data.name,
|
||||||
formData.value = {
|
auth_method: result.data.auth_method || 'token',
|
||||||
name: instance.name,
|
serverAddr: result.data.serverAddr || '',
|
||||||
auth_method: instance.auth_method || 'token',
|
serverPort: result.data.serverPort || '',
|
||||||
serverAddr: instance.serverAddr || '',
|
token: '',
|
||||||
serverPort: instance.serverPort || '',
|
clientId: '',
|
||||||
token: '',
|
clientSecret: '',
|
||||||
clientId: '',
|
audience: '',
|
||||||
clientSecret: '',
|
tokenEndpoint: '',
|
||||||
audience: '',
|
bootAtStart: result.data.bootAtStart || false,
|
||||||
tokenEndpoint: '',
|
runUser: result.data.runUser || 'root'
|
||||||
bootAtStart: instance.bootAtStart || false,
|
};
|
||||||
runUser: instance.runUser || 'root'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNotification('Load instance data failed', 'error');
|
showNotification('Load instance data failed', 'error');
|
||||||
return;
|
return;
|
||||||
@@ -497,8 +487,7 @@ export default {
|
|||||||
showNotification('Configuration saved successfully', 'success');
|
showNotification('Configuration saved successfully', 'success');
|
||||||
closeEditConfigModal();
|
closeEditConfigModal();
|
||||||
closeAddProxyModal();
|
closeAddProxyModal();
|
||||||
// 重新加载配置
|
await loadInstanceInfo();
|
||||||
await loadInstanceConfig();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNotification(error.message || 'Save configuration failed', 'error');
|
showNotification(error.message || 'Save configuration failed', 'error');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -530,8 +519,7 @@ export default {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await loadInstanceConfig();
|
await loadInstanceInfo();
|
||||||
await loadInstanceStatus();
|
|
||||||
await loadProxies();
|
await loadProxies();
|
||||||
await loadLogs();
|
await loadLogs();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -203,20 +203,30 @@ export default {
|
|||||||
|
|
||||||
const loadInstances = async () => {
|
const loadInstances = async () => {
|
||||||
try {
|
try {
|
||||||
const result = await instanceApi.listInstances();
|
const listResult = await instanceApi.listInstances();
|
||||||
instances.value = result.data.map(instance => ({
|
const instanceIDs = listResult.data.map(i => String(i.instanceID));
|
||||||
...instance,
|
|
||||||
status: 'stopped'
|
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) {
|
instances.value = listResult.data.map(instance => {
|
||||||
try {
|
const infoResult = infoResults.find(r => r && String(r.data.instanceID) === String(instance.instanceID));
|
||||||
const statusResult = await instanceApi.getInstanceStatus(String(instance.instanceID));
|
if (infoResult) {
|
||||||
instance.status = statusResult.data.isRunning ? 'running' : 'stopped';
|
return {
|
||||||
} catch (error) {
|
...instance,
|
||||||
console.error(`Failed to load status for instance ${instance.instanceID}:`, error);
|
status: infoResult.data.isRunning ? 'running' : 'stopped',
|
||||||
|
serviceName: infoResult.data.serviceName,
|
||||||
|
pid: infoResult.data.pid
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
return { ...instance, status: 'stopped' };
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNotification('Load instance list failed', 'error');
|
showNotification('Load instance list failed', 'error');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user