🏗️ refactor ServerService and index.vue to enhance HTTPS to HTTP handling and improve local file selection process

This commit is contained in:
刘嘉伟 2025-02-26 17:12:43 +08:00
parent 50adc33aef
commit 2238afa420
2 changed files with 66 additions and 22 deletions

View File

@ -67,6 +67,10 @@ class ServerService extends BaseService<OpenSourceFrpcDesktopServer> {
return proxy.status === 1; return proxy.status === 1;
} }
private isHttps2http(proxy: FrpcProxy) {
return proxy.https2http;
}
async genTomlConfig(outputPath: string) { async genTomlConfig(outputPath: string) {
if (!outputPath) { if (!outputPath) {
return; return;
@ -107,17 +111,36 @@ remotePort = {{ $v.Second }}
remotePort: remotePort remotePort: remotePort
}; };
} else if (proxy.type === "http" || proxy.type === "https") { } else if (proxy.type === "http" || proxy.type === "https") {
return { if (this.isHttps2http(proxy) && proxy.type === "https") {
name: proxy.name, return {
type: proxy.type, name: proxy.name,
localIP: proxy.localIP, type: proxy.type,
localPort: parseInt(proxy.localPort), customDomains: proxy.customDomains,
customDomains: proxy.customDomains, subdomain: proxy.subdomain,
subdomain: proxy.subdomain, ...(proxy.https2http
...(proxy.basicAuth ? {
? { httpUser: proxy.httpUser, httpPassword: proxy.httpPassword } 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 ( } else if (
proxy.type === "stcp" || proxy.type === "stcp" ||
proxy.type === "xtcp" || proxy.type === "xtcp" ||

View File

@ -9,7 +9,6 @@ import {
} from "vue"; } from "vue";
import Breadcrumb from "@/layout/compoenets/Breadcrumb.vue"; import Breadcrumb from "@/layout/compoenets/Breadcrumb.vue";
import { ElMessage, FormInstance, FormRules } from "element-plus"; import { ElMessage, FormInstance, FormRules } from "element-plus";
import { ipcRenderer } from "electron";
import { useClipboard, useDebounceFn } from "@vueuse/core"; import { useClipboard, useDebounceFn } from "@vueuse/core";
import IconifyIconOffline from "@/components/IconifyIcon/src/iconifyIconOffline"; import IconifyIconOffline from "@/components/IconifyIcon/src/iconifyIconOffline";
import commonIps from "./commonIp.json"; import commonIps from "./commonIp.json";
@ -83,6 +82,7 @@ const editForm = ref<FrpcProxy>(_.cloneDeep(defaultForm));
* 代理类型 * 代理类型
*/ */
const proxyTypes = ref(["http", "https", "tcp", "udp", "stcp", "xtcp", "sudp"]); const proxyTypes = ref(["http", "https", "tcp", "udp", "stcp", "xtcp", "sudp"]);
const currSelectLocalFileType = ref();
const visitorsModels = ref([ const visitorsModels = ref([
{ {
@ -157,6 +157,7 @@ const editFormRules = reactive<FormRules>({
httpPassword: [{ required: true, message: "请输入认证密码", trigger: "blur" }] httpPassword: [{ required: true, message: "请输入认证密码", trigger: "blur" }]
}); });
/** /**
* 表单dom * 表单dom
*/ */
@ -506,17 +507,22 @@ const normalizePath = (filePath: string) => {
}; };
const handleSelectFile = (type: number, ext: string[]) => { const handleSelectFile = (type: number, ext: string[]) => {
ipcRenderer.invoke("file.selectFile", ext).then(r => { currSelectLocalFileType.value = type;
switch (type) { send(ipcRouters.SYSTEM.selectLocalFile, {
case 1: name: "",
editForm.value.https2httpCaFile = normalizePath(r[0]); extensions: ext
break;
case 2:
editForm.value.https2httpKeyFile = normalizePath(r[0]);
break;
}
console.log(r);
}); });
// 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(() => { onMounted(() => {
@ -528,6 +534,20 @@ onMounted(() => {
proxys.value = data; 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) => { const insertOrUpdateHook = (message: string) => {
loading.value.form--; loading.value.form--;
// const { err } = args; // const { err } = args;
@ -601,6 +621,7 @@ onUnmounted(() => {
removeRouterListeners(ipcRouters.PROXY.getAllProxies); removeRouterListeners(ipcRouters.PROXY.getAllProxies);
removeRouterListeners(ipcRouters.PROXY.modifyProxyStatus); removeRouterListeners(ipcRouters.PROXY.modifyProxyStatus);
removeRouterListeners(ipcRouters.PROXY.getLocalPorts); removeRouterListeners(ipcRouters.PROXY.getLocalPorts);
removeRouterListeners(ipcRouters.SYSTEM.selectLocalFile);
}); });
</script> </script>
<template> <template>