部分重型模块的原子化拆解
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// modules/config.js
|
||||
import { apiFetch } from './api.js';
|
||||
|
||||
const defaultConfig = {
|
||||
serverAddr: 'frp.whitetop.xyz',
|
||||
serverPort: 9358,
|
||||
token: '',
|
||||
logLevel: 'info',
|
||||
logMaxDays: 3,
|
||||
tcpMux: true,
|
||||
tcpMuxKeepalive: 30,
|
||||
heartbeatInterval: 15,
|
||||
heartbeatTimeout: 70,
|
||||
poolCount: 8,
|
||||
};
|
||||
|
||||
export async function loadConfig() {
|
||||
try {
|
||||
const data = await apiFetch('/config');
|
||||
if (data.code === 0) {
|
||||
return { ...defaultConfig, ...data.data };
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('加载配置失败', e);
|
||||
}
|
||||
return { ...defaultConfig };
|
||||
}
|
||||
|
||||
export async function saveConfig(config) {
|
||||
const data = await apiFetch('/config', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(config),
|
||||
});
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user