- Change API endpoint from POST to GET for instance status - Update proxy target URL in vite config - Add instance name display and remove initSystem from detail view - Improve instance data handling in InstanceDetail component
116 lines
3.7 KiB
JavaScript
116 lines
3.7 KiB
JavaScript
import axios from 'axios';
|
|
import { getCookie } from '../utils/functions.js';
|
|
|
|
const api = axios.create({
|
|
baseURL: '/api',
|
|
timeout: 10000
|
|
});
|
|
|
|
api.interceptors.request.use(
|
|
config => {
|
|
const token = getCookie('token');
|
|
if (token) {
|
|
config.headers['X-Token'] = token;
|
|
}
|
|
config.headers['X-Timestamp'] = Date.now();
|
|
return config;
|
|
},
|
|
error => {
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
api.interceptors.response.use(
|
|
response => {
|
|
return response.data;
|
|
},
|
|
error => {
|
|
if (error.response) {
|
|
return Promise.reject(error.response.data);
|
|
}
|
|
return Promise.reject({ success: false, message: 'Network error' });
|
|
}
|
|
);
|
|
|
|
export const systemApi = {
|
|
getStatus: () => api.get('/system/getStatus'),
|
|
getSoftwareInfo: () => api.get('/system/getSoftwareInfo')
|
|
};
|
|
|
|
export const authApi = {
|
|
register: (username, passwd, type = 'visitor') =>
|
|
api.post('/register', { username, passwd, type }),
|
|
login: (username, passwd) =>
|
|
api.post('/login', { username, passwd }),
|
|
logout: () => api.get('/logout')
|
|
};
|
|
|
|
export const userApi = {
|
|
createUser: (username, passwd, type) =>
|
|
api.post('/userMgr/create', { username, passwd, type }),
|
|
removeUser: (targetUserID) =>
|
|
api.post('/userMgr/remove', { targetUserID }),
|
|
listUsers: () => api.get('/userMgr/list')
|
|
};
|
|
|
|
export const sessionApi = {
|
|
listSessions: () => api.get('/sessionMgr/list'),
|
|
removeSession: (sessionID) =>
|
|
api.post('/sessionMgr/remove', { sessionID })
|
|
};
|
|
|
|
export const instanceApi = {
|
|
createInstance: (instanceInfo, bootAtStart, runUser, additionalProperties) =>
|
|
api.post('/frpcAct/instanceMgr/create', {
|
|
instanceInfo,
|
|
bootAtStart,
|
|
runUser,
|
|
additionalProperties
|
|
}),
|
|
deleteInstance: (instanceID) =>
|
|
api.post('/frpcAct/instanceMgr/delete', { instanceID }),
|
|
modifyInstance: (instanceID, type, modifiedData) =>
|
|
api.post('/frpcAct/instanceMgr/modify', {
|
|
instanceID,
|
|
type,
|
|
modifiedData
|
|
}),
|
|
listInstances: () => api.get('/frpcAct/instanceMgr/list'),
|
|
startInstance: (instanceID) =>
|
|
api.post('/frpcAct/instanceMgr/start', { instanceID }),
|
|
stopInstance: (instanceID) =>
|
|
api.post('/frpcAct/instanceMgr/stop', { instanceID }),
|
|
restartInstance: (instanceID) =>
|
|
api.post('/frpcAct/instanceMgr/restart', { instanceID }),
|
|
getInstanceStatus: (instanceID) =>
|
|
api.get(`/frpcAct/instanceMgr/status?instanceID=${instanceID}`),
|
|
getInstanceLogs: (instanceID) =>
|
|
api.post('/frpcAct/instanceMgr/logs', { instanceID }),
|
|
getInstanceProxies: (instanceID) =>
|
|
api.get(`/frpcAct/proxyMgr/list?instanceID=${instanceID}`),
|
|
createProxy: (instanceID, proxyInfo) =>
|
|
api.post('/frpcAct/proxyMgr/create', { instanceID, proxyInfo })
|
|
};
|
|
|
|
export const logApi = {
|
|
getLogs: (level) => api.post('/logMgr/list', { level })
|
|
};
|
|
|
|
export const monitorApi = {
|
|
getSystemStats: () => api.get('/monitor/stats')
|
|
};
|
|
|
|
export const systemInfoApi = {
|
|
getSystemInfo: () => api.get('/system/info')
|
|
};
|
|
|
|
export default api;
|
|
|
|
export const TODO_API_NOTES = {
|
|
instanceLogs: 'TODO: /frpcAct/instanceMgr/logs - 获取实例日志 API 未在 api-backend.md 中定义',
|
|
instanceProxies: 'TODO: /frpcAct/instanceMgr/proxies - 获取实例代理列表 API 未在 api-backend.md 中定义',
|
|
logList: 'TODO: /logMgr/list - 获取系统日志 API 未在 api-backend.md 中定义',
|
|
monitorStats: 'TODO: /monitor/stats - 获取系统监控数据 API 未在 api-backend.md 中定义',
|
|
systemInfo: 'TODO: /system/info - 获取系统信息 API 未在 api-backend.md 中定义'
|
|
};
|