118 lines
3.9 KiB
JavaScript
118 lines
3.9 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'),
|
|
getSystemInfo: () => api.get('/system/info'),
|
|
selfCheck: () => api.get('/system/selfCheck'),
|
|
getSettings: (key) => {
|
|
const url = key ? `/system/settings/get?key=${key}` : '/system/settings/get';
|
|
return api.get(url);
|
|
},
|
|
setSettings: (settings) =>
|
|
api.post('/system/settings/set', settings),
|
|
restartServer: () => api.get('/system/restart')
|
|
};
|
|
|
|
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'),
|
|
modifyUser: (userID, username, passwd) =>
|
|
api.post(`/userMgr/modify`, { userID, username, passwd }),
|
|
modifyType: (userID, newType) =>
|
|
api.post(`/userMgr/modifyType`, { userID, newType: newType.toLowerCase() || 'visitor' })
|
|
};
|
|
|
|
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 }),
|
|
getInstanceInfo: (instanceID) =>
|
|
api.get(`/frpcAct/instanceMgr/getInfo?instanceID=${instanceID}`),
|
|
getInstanceStatus: (instanceID) =>
|
|
api.get(`/frpcAct/instanceMgr/status?instanceID=${instanceID}`),
|
|
getInstanceProxies: (instanceID) =>
|
|
api.get(`/frpcAct/proxyMgr/list?instanceID=${instanceID}`),
|
|
createProxy: (instanceID, proxyInfo) =>
|
|
api.post('/frpcAct/proxyMgr/create', { instanceID, proxyInfo }),
|
|
modifyProxy: (instanceID, proxyInfo) =>
|
|
api.post('/frpcAct/proxyMgr/modify', { instanceID, proxyInfo }),
|
|
deleteProxy: (instanceID, proxyName) =>
|
|
api.post('/frpcAct/proxyMgr/delete', { instanceID, proxyName })
|
|
};
|
|
|
|
export const logApi = {
|
|
getLogs: (level) => api.post('/logMgr/list', { level })
|
|
};
|
|
|
|
export default api;
|