Improve code

This commit is contained in:
Younes Aassila 2025-02-07 16:15:33 +01:00
parent de97812b24
commit 6df1cc7638
No known key found for this signature in database
3 changed files with 5 additions and 5 deletions

View File

@ -14,9 +14,9 @@ export function getProxyInfoFromUrl(
): ProxyInfo & { host: string; port: number } { ): ProxyInfo & { host: string; port: number } {
let type: ProxyType | undefined = undefined; let type: ProxyType | undefined = undefined;
if (url.includes("://")) { if (url.includes("://")) {
const [protocol, urlWithoutProtocol] = url.split("://", 2); const [protocol] = url.split("://", 1);
type = protocol as ProxyType; type = protocol as ProxyType;
url = urlWithoutProtocol; url = url.substring(protocol.length + 3, url.length);
} }
const lastIndexOfAt = url.lastIndexOf("@"); const lastIndexOfAt = url.lastIndexOf("@");

View File

@ -15,8 +15,8 @@ const PROXY_TYPE_MAP: Readonly<Record<ProxyType, string>> = Object.freeze({
direct: "DIRECT", direct: "DIRECT",
http: "PROXY", http: "PROXY",
https: "HTTPS", https: "HTTPS",
socks4: "SOCKS4",
socks: "SOCKS5", socks: "SOCKS5",
socks4: "SOCKS4",
}); });
export function updateProxySettings(requestFilter?: ProxyRequestType[]) { export function updateProxySettings(requestFilter?: ProxyRequestType[]) {

View File

@ -346,13 +346,13 @@ function isOptimizedProxyUrlAllowed(url: string): AllowedResult {
} }
if (url.includes("://")) { if (url.includes("://")) {
const [protocol, urlWithoutProtocol] = url.split("://", 2); const [protocol] = url.split("://", 1);
if (!store.state.allowOtherProxyProtocols) { if (!store.state.allowOtherProxyProtocols) {
return [false, "Proxy URLs must not contain a protocol (e.g. 'http://')"]; return [false, "Proxy URLs must not contain a protocol (e.g. 'http://')"];
} else if (!["http", "https", "socks", "socks4"].includes(protocol)) { } else if (!["http", "https", "socks", "socks4"].includes(protocol)) {
return [false, `'${protocol}' is not a supported protocol`]; return [false, `'${protocol}' is not a supported protocol`];
} }
url = urlWithoutProtocol; url = url.substring(protocol.length + 3, url.length);
} }
if (url.includes("/")) { if (url.includes("/")) {