From 2238afa4200b029d255361e78b5f7ff0b7ee67f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=98=89=E4=BC=9F?= <8473136@qq.com> Date: Wed, 26 Feb 2025 17:12:43 +0800 Subject: [PATCH] :building_construction: refactor ServerService and index.vue to enhance HTTPS to HTTP handling and improve local file selection process --- electron/service/ServerService.ts | 45 +++++++++++++++++++++++-------- src/views/proxy/index.vue | 43 +++++++++++++++++++++-------- 2 files changed, 66 insertions(+), 22 deletions(-) diff --git a/electron/service/ServerService.ts b/electron/service/ServerService.ts index d08b732..9ca824f 100644 --- a/electron/service/ServerService.ts +++ b/electron/service/ServerService.ts @@ -67,6 +67,10 @@ class ServerService extends BaseService { return proxy.status === 1; } + private isHttps2http(proxy: FrpcProxy) { + return proxy.https2http; + } + async genTomlConfig(outputPath: string) { if (!outputPath) { return; @@ -107,17 +111,36 @@ remotePort = {{ $v.Second }} remotePort: remotePort }; } else if (proxy.type === "http" || proxy.type === "https") { - return { - name: proxy.name, - type: proxy.type, - localIP: proxy.localIP, - localPort: parseInt(proxy.localPort), - customDomains: proxy.customDomains, - subdomain: proxy.subdomain, - ...(proxy.basicAuth - ? { httpUser: proxy.httpUser, httpPassword: proxy.httpPassword } - : {}) - }; + if (this.isHttps2http(proxy) && proxy.type === "https") { + return { + name: proxy.name, + type: proxy.type, + customDomains: proxy.customDomains, + subdomain: proxy.subdomain, + ...(proxy.https2http + ? { + plugin: { + type: "https2http", + localAddr: `${proxy.localIP}:${proxy.localPort}`, + crtPath: proxy.https2httpCaFile, + keyPath: proxy.https2httpKeyFile + } + } + : {}) + }; + } else { + return { + name: proxy.name, + type: proxy.type, + localIP: proxy.localIP, + localPort: parseInt(proxy.localPort), + customDomains: proxy.customDomains, + subdomain: proxy.subdomain, + ...(proxy.basicAuth + ? { httpUser: proxy.httpUser, httpPassword: proxy.httpPassword } + : {}) + }; + } } else if ( proxy.type === "stcp" || proxy.type === "xtcp" || diff --git a/src/views/proxy/index.vue b/src/views/proxy/index.vue index 972a1cb..e37805b 100644 --- a/src/views/proxy/index.vue +++ b/src/views/proxy/index.vue @@ -9,7 +9,6 @@ import { } from "vue"; import Breadcrumb from "@/layout/compoenets/Breadcrumb.vue"; import { ElMessage, FormInstance, FormRules } from "element-plus"; -import { ipcRenderer } from "electron"; import { useClipboard, useDebounceFn } from "@vueuse/core"; import IconifyIconOffline from "@/components/IconifyIcon/src/iconifyIconOffline"; import commonIps from "./commonIp.json"; @@ -83,6 +82,7 @@ const editForm = ref(_.cloneDeep(defaultForm)); * 代理类型 */ const proxyTypes = ref(["http", "https", "tcp", "udp", "stcp", "xtcp", "sudp"]); +const currSelectLocalFileType = ref(); const visitorsModels = ref([ { @@ -157,6 +157,7 @@ const editFormRules = reactive({ httpPassword: [{ required: true, message: "请输入认证密码", trigger: "blur" }] }); + /** * 表单dom */ @@ -506,17 +507,22 @@ const normalizePath = (filePath: string) => { }; const handleSelectFile = (type: number, ext: string[]) => { - ipcRenderer.invoke("file.selectFile", ext).then(r => { - switch (type) { - case 1: - editForm.value.https2httpCaFile = normalizePath(r[0]); - break; - case 2: - editForm.value.https2httpKeyFile = normalizePath(r[0]); - break; - } - console.log(r); + currSelectLocalFileType.value = type; + send(ipcRouters.SYSTEM.selectLocalFile, { + name: "", + extensions: ext }); + // ipcRenderer.invoke("file.selectFile", ext).then(r => { + // switch (type) { + // case 1: + // editForm.value.https2httpCaFile = normalizePath(r[0]); + // break; + // case 2: + // editForm.value.https2httpKeyFile = normalizePath(r[0]); + // break; + // } + // console.log(r); + // }); }; onMounted(() => { @@ -528,6 +534,20 @@ onMounted(() => { proxys.value = data; }); + on(ipcRouters.SYSTEM.selectLocalFile, data => { + console.log("data", data); + if (!data.canceled) { + switch (currSelectLocalFileType.value) { + case 1: + editForm.value.https2httpCaFile = data.path as string; + break; + case 2: + editForm.value.https2httpKeyFile = data.path as string; + break; + } + } + }); + const insertOrUpdateHook = (message: string) => { loading.value.form--; // const { err } = args; @@ -601,6 +621,7 @@ onUnmounted(() => { removeRouterListeners(ipcRouters.PROXY.getAllProxies); removeRouterListeners(ipcRouters.PROXY.modifyProxyStatus); removeRouterListeners(ipcRouters.PROXY.getLocalPorts); + removeRouterListeners(ipcRouters.SYSTEM.selectLocalFile); });