Skip to content

Let's use AI to Earn!

feat: 代理添加解析格式

gaoSir8e980929f979
diff --git a/commont/utils.ts b/commont/utils.ts
index fdef43e9..3842d4b5 100644
--- a/commont/utils.ts
+++ b/commont/utils.ts
@@ -1,4 +1,7 @@
// 根据文件路径获取文件名和后缀
+import { ProxyInfo } from '@@/utils.type';
+
+// 提取路径中的文件名
export function getFilePathNameCommon(path: string) {
if (!path)
return {
@@ -45,3 +48,28 @@ export async function RetryWhile(
}
return flag;
}
+
+/**
+ * 代理解析
+ * @param proxyString
+ */
+export function parseProxyString(proxyString: string): ProxyInfo | false {
+ const regex =
+ /^(?:(\w+):\/\/)?([\d.]+:\d+)(?::([^:]+):([^{}\s]+))?(?:\[(.*?)\])?(?:{(.*?)})?$/;
+
+ const match = proxyString.match(regex);
+ if (!match) {
+ return false; // 无法解析则返回 false
+ }
+
+ const [, protocol, ipAndPort, username, password, refreshUrl, remark] = match;
+
+ return {
+ protocol: protocol || 'http', // 如果未提供协议,默认为 http
+ ipAndPort,
+ username,
+ password,
+ refreshUrl,
+ remark,
+ };
+}
diff --git a/commont/utils.type.ts b/commont/utils.type.ts
new file mode 100644
index 00000000..8910c043
--- /dev/null
+++ b/commont/utils.type.ts
@@ -0,0 +1,14 @@
+export interface ProxyInfo {
+ // 协议: 如 http, socks5
+ protocol: string;
+ // IP+端口: 如 192.168.0.1:8000
+ ipAndPort: string;
+ // 代理账号: 可选
+ username?: string;
+ // 代理密码: 可选
+ password?: string;
+ // 刷新URL: 可选
+ refreshUrl?: string;
+ // 备注: 可选
+ remark?: string;
+}
diff --git a/electron/plat/bilibili/index.ts b/electron/plat/bilibili/index.ts
index 45970771..d8311eac 100644
--- a/electron/plat/bilibili/index.ts
+++ b/electron/plat/bilibili/index.ts
@@ -122,6 +122,7 @@ class Bilibili {
* 视频稿件提交
* @param accessToken
* @param uploadToken
+ * @param data
* @returns
*/
async archiveAddByUtoken(
diff --git a/electron/plat/requestNet.ts b/electron/plat/requestNet.ts
index b487fa10..4ee191a2 100644
--- a/electron/plat/requestNet.ts
+++ b/electron/plat/requestNet.ts
@@ -1,6 +1,7 @@
import { net, session, Session } from 'electron';
import FormData from 'form-data';
import { ipv4Regular } from '../../commont/regular';
+import { parseProxyString } from '../../commont/utils';
export interface IRequestNetResult<T> {
status: number;
@@ -38,13 +39,18 @@ const requestNet = <T = any>({
// 如果传入了代理配置,动态设置代理
if (proxy) {
- if (!ipv4Regular.test(proxy)) throw new Error('代理地址不合法');
+ // 解析代理信息
+ const proxyInfo = parseProxyString(proxy);
+ if (proxyInfo === false || !ipv4Regular.test(proxyInfo.ipAndPort))
+ throw new Error('代理地址不合法');
customSession = session.fromPartition(
`persist:proxy-session-${Date.now()}`,
);
- console.log(`http=${proxy};https=${proxy}`);
+ const proxyUrl = `${proxyInfo.protocol}://${proxyInfo.ipAndPort}`;
+ const proxyRules = `http=${proxyUrl};https=${proxyUrl}`;
+ console.log(proxyRules);
await customSession.setProxy({
- proxyRules: `http=${proxy};https=${proxy}`,
+ proxyRules,
});
headers = {
diff --git a/src/views/account/components/AccountSidebar/ProxyManage/index.tsx b/src/views/account/components/AccountSidebar/ProxyManage/index.tsx
index 66e99b26..8fa65c54 100644
--- a/src/views/account/components/AccountSidebar/ProxyManage/index.tsx
+++ b/src/views/account/components/AccountSidebar/ProxyManage/index.tsx
@@ -13,6 +13,7 @@ import { useShallow } from 'zustand/react/shallow';
import { QuestionCircleOutlined, SearchOutlined } from '@ant-design/icons';
import accountStyles from '../AccountSidebar.module.scss';
import { icpEditDeleteAccountGroup, icpProxyCheck } from '@/icp/account';
+import {parseProxyString} from "@@/utils";
export interface IProxyManageRef {}
@@ -193,6 +194,7 @@ const ProxyManage = memo(
disabled={proxyName.length === 0}
loading={proxyLoading}
onClick={async () => {
+ console.log(parseProxyString(proxyName));
setProxyLoading(true);
const res = await icpProxyCheck(proxyName);
setProxyLoading(false);