Initial commit: finish basic WebUI interface
This commit is contained in:
115
src/api/index.js
Normal file
115
src/api/index.js
Normal file
@@ -0,0 +1,115 @@
|
||||
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('login-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: (instanceName) =>
|
||||
api.post('/frpcAct/instanceMgr/delete', { instanceName }),
|
||||
modifyInstance: (instanceName, instanceID, type, modifiedData) =>
|
||||
api.post('/frpcAct/instanceMgr/modify', {
|
||||
instanceName,
|
||||
instanceID,
|
||||
type,
|
||||
modifiedData
|
||||
}),
|
||||
listInstances: () => api.get('/frpcAct/instanceMgr/list'),
|
||||
startInstance: (instanceName) =>
|
||||
api.post('/frpcAct/instanceMgr/start', { instanceName }),
|
||||
stopInstance: (instanceName) =>
|
||||
api.post('/frpcAct/instanceMgr/stop', { instanceName }),
|
||||
restartInstance: (instanceName) =>
|
||||
api.post('/frpcAct/instanceMgr/restart', { instanceName }),
|
||||
getInstanceLogs: (instanceName) =>
|
||||
api.get('/frpcAct/instanceMgr/logs', { params: { instanceName } }),
|
||||
getInstanceProxies: (instanceName) =>
|
||||
api.get('/frpcAct/instanceMgr/proxies', { params: { instanceName } })
|
||||
};
|
||||
|
||||
export const logApi = {
|
||||
getLogs: (level) => api.get('/logMgr/list', { params: { 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 = {
|
||||
instanceStart: 'TODO: /frpcAct/instanceMgr/start - 启动实例 API 未在 api-backend.md 中定义',
|
||||
instanceStop: 'TODO: /frpcAct/instanceMgr/stop - 停止实例 API 未在 api-backend.md 中定义',
|
||||
instanceRestart: 'TODO: /frpcAct/instanceMgr/restart - 重启实例 API 未在 api-backend.md 中定义',
|
||||
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 中定义'
|
||||
};
|
||||
Reference in New Issue
Block a user