mirror of
https://github.com/younesaassila/ttv-lol-pro.git
synced 2025-04-29 22:14:27 +02:00
fix: fallback to protocols default port for onAuthRequired
This commit is contained in:
parent
62e34f55b0
commit
a7e7aa0e93
@ -1,7 +1,7 @@
|
|||||||
import { Address6 } from "ip-address";
|
import { Address6 } from "ip-address";
|
||||||
import type { ProxyInfo, ProxyScheme } from "../../types";
|
import type { ProxyInfo } from "../../types";
|
||||||
|
|
||||||
export const proxySchemes: { [key: string]: ProxyScheme } = {
|
export const proxySchemes = {
|
||||||
direct: "DIRECT",
|
direct: "DIRECT",
|
||||||
http: "PROXY",
|
http: "PROXY",
|
||||||
https: "HTTPS",
|
https: "HTTPS",
|
||||||
@ -9,19 +9,32 @@ export const proxySchemes: { [key: string]: ProxyScheme } = {
|
|||||||
socks4: "SOCKS4",
|
socks4: "SOCKS4",
|
||||||
socks5: "SOCKS5",
|
socks5: "SOCKS5",
|
||||||
quic: "QUIC",
|
quic: "QUIC",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
type Protocol = keyof typeof proxySchemes;
|
||||||
|
|
||||||
|
const defaultPorts: Partial<{
|
||||||
|
[key in keyof typeof proxySchemes]: number;
|
||||||
|
}> = {
|
||||||
|
http: 80,
|
||||||
|
https: 443,
|
||||||
|
socks: 1080,
|
||||||
|
socks4: 1080,
|
||||||
|
socks5: 1080,
|
||||||
|
quic: 443,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getProxyInfoFromUrl(url: string) {
|
export function getProxyInfoFromUrl(url: string) {
|
||||||
let protocol = "";
|
let protocol = "";
|
||||||
if (url.includes("://")) {
|
if (url.includes("://")) {
|
||||||
let [proto, urlWithoutProtocol] = url.split("://");
|
let [_protocol, urlWithoutProtocol] = url.split("://");
|
||||||
protocol = proto;
|
protocol = _protocol;
|
||||||
url = urlWithoutProtocol;
|
url = urlWithoutProtocol;
|
||||||
}
|
}
|
||||||
const lastIndexOfAt = url.lastIndexOf("@");
|
const lastIndexOfAt = url.lastIndexOf("@");
|
||||||
let hostname = url.substring(lastIndexOfAt + 1, url.length);
|
let hostname = url.substring(lastIndexOfAt + 1, url.length);
|
||||||
const lastIndexOfColon = getLastIndexOfColon(hostname);
|
const lastIndexOfColon = getLastIndexOfColon(hostname);
|
||||||
hostname;
|
|
||||||
let host: string | undefined = undefined;
|
let host: string | undefined = undefined;
|
||||||
let port: number | undefined = undefined;
|
let port: number | undefined = undefined;
|
||||||
if (lastIndexOfColon === -1) {
|
if (lastIndexOfColon === -1) {
|
||||||
@ -46,8 +59,10 @@ export function getProxyInfoFromUrl(url: string) {
|
|||||||
password = credentials.substring(indexOfColon + 1, credentials.length);
|
password = credentials.substring(indexOfColon + 1, credentials.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
port = port ? port : defaultPorts[protocol as Protocol];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: proxySchemes[protocol] ?? "PROXY",
|
type: proxySchemes[protocol as Protocol] ?? "PROXY",
|
||||||
protocol,
|
protocol,
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
|
@ -16,9 +16,10 @@ import sendAdLog from "../common/ts/sendAdLog";
|
|||||||
import store from "../store";
|
import store from "../store";
|
||||||
import getDefaultState from "../store/getDefaultState";
|
import getDefaultState from "../store/getDefaultState";
|
||||||
import type { State } from "../store/types";
|
import type { State } from "../store/types";
|
||||||
import { AllowedResult, KeyOfType, ProxyRequestType } from "../types";
|
import { KeyOfType, ProxyRequestType } from "../types";
|
||||||
|
|
||||||
//#region Types
|
//#region Types
|
||||||
|
type AllowedResult = [boolean, string?];
|
||||||
type InsertMode = "append" | "prepend" | "both";
|
type InsertMode = "append" | "prepend" | "both";
|
||||||
type StoreStringArrayKey = KeyOfType<typeof store.state, string[]>;
|
type StoreStringArrayKey = KeyOfType<typeof store.state, string[]>;
|
||||||
type ListOptions = {
|
type ListOptions = {
|
||||||
|
@ -3,8 +3,6 @@ export type KeyOfType<T, V> = keyof {
|
|||||||
[P in keyof T as T[P] extends V ? P : never]: any;
|
[P in keyof T as T[P] extends V ? P : never]: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AllowedResult = [boolean, string?];
|
|
||||||
|
|
||||||
// From https://chromium.googlesource.com/chromium/src/+/HEAD/net/docs/proxy.md#proxy-server-schemes
|
// From https://chromium.googlesource.com/chromium/src/+/HEAD/net/docs/proxy.md#proxy-server-schemes
|
||||||
export type ProxyScheme =
|
export type ProxyScheme =
|
||||||
| "DIRECT"
|
| "DIRECT"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user