🏗️ refactor file selection handling to improve response structure and utilize path data in SystemController
This commit is contained in:
parent
ce709fe5e7
commit
f77605a73d
@ -3,14 +3,12 @@ import ServerRepository from "../repository/ServerRepository";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import PathUtils from "../utils/PathUtils";
|
import PathUtils from "../utils/PathUtils";
|
||||||
import ProxyRepository from "../repository/ProxyRepository";
|
import ProxyRepository from "../repository/ProxyRepository";
|
||||||
import SystemService from "./SystemService";
|
|
||||||
import { BrowserWindow, dialog } from "electron";
|
import { BrowserWindow, dialog } from "electron";
|
||||||
import BeanFactory from "../core/BeanFactory";
|
import BeanFactory from "../core/BeanFactory";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import GlobalConstant from "../core/GlobalConstant";
|
import GlobalConstant from "../core/GlobalConstant";
|
||||||
import TOML from "smol-toml";
|
import TOML from "smol-toml";
|
||||||
|
|
||||||
|
|
||||||
class ServerService extends BaseService<OpenSourceFrpcDesktopServer> {
|
class ServerService extends BaseService<OpenSourceFrpcDesktopServer> {
|
||||||
private readonly _serverDao: ServerRepository;
|
private readonly _serverDao: ServerRepository;
|
||||||
private readonly _proxyDao: ProxyRepository;
|
private readonly _proxyDao: ProxyRepository;
|
||||||
@ -19,7 +17,7 @@ class ServerService extends BaseService<OpenSourceFrpcDesktopServer> {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
serverDao: ServerRepository,
|
serverDao: ServerRepository,
|
||||||
proxyDao: ProxyRepository,
|
proxyDao: ProxyRepository
|
||||||
// systemService: SystemService
|
// systemService: SystemService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
@ -59,8 +57,36 @@ class ServerService extends BaseService<OpenSourceFrpcDesktopServer> {
|
|||||||
const enabledProxies = proxies
|
const enabledProxies = proxies
|
||||||
.filter(f => f.status === 1)
|
.filter(f => f.status === 1)
|
||||||
.map(proxy => {
|
.map(proxy => {
|
||||||
|
if (proxy.type === "tcp") {
|
||||||
|
const {
|
||||||
|
_id,
|
||||||
|
status,
|
||||||
|
basicAuth,
|
||||||
|
bindAddr,
|
||||||
|
subdomain,
|
||||||
|
httpUser,
|
||||||
|
httpPassword,
|
||||||
|
fallbackTo,
|
||||||
|
fallbackTimeoutMs,
|
||||||
|
https2http,
|
||||||
|
https2httpCaFile,
|
||||||
|
https2httpKeyFile,
|
||||||
|
stcpModel,
|
||||||
|
customDomains,
|
||||||
|
locations,
|
||||||
|
hostHeaderRewrite,
|
||||||
|
keepTunnelOpen,
|
||||||
|
secretKey,
|
||||||
|
serverName,
|
||||||
|
...frpProxyConfig
|
||||||
|
} = proxy;
|
||||||
|
frpProxyConfig.localPort = parseInt(frpProxyConfig.localPort);
|
||||||
|
frpProxyConfig.remotePort = parseInt(frpProxyConfig.remotePort);
|
||||||
|
return frpProxyConfig;
|
||||||
|
} else {
|
||||||
const { _id, status, ...frpProxyConfig } = proxy;
|
const { _id, status, ...frpProxyConfig } = proxy;
|
||||||
return frpProxyConfig;
|
return frpProxyConfig;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const { frpcVersion, _id, system, ...commonConfig } = server;
|
const { frpcVersion, _id, system, ...commonConfig } = server;
|
||||||
const frpcConfig = { ...commonConfig };
|
const frpcConfig = { ...commonConfig };
|
||||||
@ -80,12 +106,9 @@ class ServerService extends BaseService<OpenSourceFrpcDesktopServer> {
|
|||||||
const win: BrowserWindow = BeanFactory.getBean("win");
|
const win: BrowserWindow = BeanFactory.getBean("win");
|
||||||
const result = await dialog.showOpenDialog(win, {
|
const result = await dialog.showOpenDialog(win, {
|
||||||
properties: ["openFile"],
|
properties: ["openFile"],
|
||||||
filters: [
|
filters: [{ name: "Frpc Toml ConfigFile", extensions: ["toml"] }]
|
||||||
{ name: "Frpc Toml ConfigFile", extensions: ["toml"] }
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
if (result.canceled) {
|
if (result.canceled) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const filePath = result.filePaths[0];
|
const filePath = result.filePaths[0];
|
||||||
const fileExtension = path.extname(filePath);
|
const fileExtension = path.extname(filePath);
|
||||||
|
@ -45,8 +45,8 @@ onMounted(() => {
|
|||||||
(bizCode: string, message: string) => {
|
(bizCode: string, message: string) => {
|
||||||
if (bizCode === "B1001") {
|
if (bizCode === "B1001") {
|
||||||
ElMessageBox.alert("请先前往设置页面,修改配置后再启动", "提示", {
|
ElMessageBox.alert("请先前往设置页面,修改配置后再启动", "提示", {
|
||||||
showCancelButton: true,
|
// showCancelButton: true,
|
||||||
cancelButtonText: "取消",
|
// cancelButtonText: "取消",
|
||||||
confirmButtonText: "去设置"
|
confirmButtonText: "去设置"
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
router.replace({
|
router.replace({
|
||||||
|
Loading…
Reference in New Issue
Block a user