🏗️ 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;
}
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" ||

View File

@ -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<FrpcProxy>(_.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<FormRules>({
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);
});
</script>
<template>