mirror of
https://github.com/EasyTier/EasytierGame.git
synced 2025-05-19 10:27:56 +00:00
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { BaseDirectory, writeTextFile } from "@tauri-apps/plugin-fs";
|
|
import useMainStore from "@/stores/index";
|
|
import { ElMessage } from "element-plus";
|
|
import { uniq, intersection, isNil } from "lodash-es";
|
|
export const updateConfigJson = async (configJsonSeverUrl: Array<string> | string | null | undefined) => {
|
|
const mainStore = useMainStore();
|
|
const path = import.meta.env.VITE_CONFIG_FILE_NAME;
|
|
if (isNil(configJsonSeverUrl)) {
|
|
configJsonSeverUrl = [];
|
|
}
|
|
const isArray = Array.isArray(configJsonSeverUrl);
|
|
const isString = typeof configJsonSeverUrl === "string";
|
|
try {
|
|
const {
|
|
proxyNetworks,
|
|
autoStart,
|
|
relayAllPeerrpc,
|
|
connectAfterStart,
|
|
multiThread,
|
|
enablExitNode,
|
|
useSmoltcp,
|
|
saveErrorLog,
|
|
logLevel,
|
|
serverUrl,
|
|
...otherConfig
|
|
} = mainStore.config;
|
|
let writeServerUrl: Array<string> | string = serverUrl;
|
|
if (isArray) {
|
|
writeServerUrl = intersection(
|
|
uniq([serverUrl, ...configJsonSeverUrl]).filter(boolean => boolean),
|
|
mainStore.basePeers
|
|
);
|
|
}
|
|
if (isString && configJsonSeverUrl) {
|
|
writeServerUrl = intersection(
|
|
uniq([serverUrl, ...(configJsonSeverUrl as string).split(",")]).filter(boolean => boolean),
|
|
mainStore.basePeers
|
|
).join(",");
|
|
}
|
|
await writeTextFile(path, JSON.stringify({ serverUrl: writeServerUrl, ...otherConfig }, null, 4), { baseDir: BaseDirectory.Resource });
|
|
} catch (err) {
|
|
console.error(err);
|
|
ElMessage.error(`更新config.json失败`);
|
|
}
|
|
};
|