mirror of
https://github.com/younesaassila/ttv-lol-pro.git
synced 2025-05-09 02:44:29 +02:00
feat: add support for additional proxy protocols
This commit is contained in:
parent
aaf1961913
commit
62e34f55b0
@ -38,7 +38,7 @@ export default function onBeforeVideoWeaverRequest(
|
|||||||
textLower.includes("https://example.com") &&
|
textLower.includes("https://example.com") &&
|
||||||
textLower.includes("https://help.twitch.tv/");
|
textLower.includes("https://help.twitch.tv/");
|
||||||
const proxy =
|
const proxy =
|
||||||
details.proxyInfo && details.proxyInfo.type !== "direct"
|
details.proxyInfo && details.proxyInfo.type !== "DIRECT"
|
||||||
? getUrlFromProxyInfo(details.proxyInfo)
|
? getUrlFromProxyInfo(details.proxyInfo)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ function getProxyFromDetails(
|
|||||||
return getUrlFromProxyInfo(possibleProxies[0]);
|
return getUrlFromProxyInfo(possibleProxies[0]);
|
||||||
} else {
|
} else {
|
||||||
const proxyInfo = details.proxyInfo; // Firefox only.
|
const proxyInfo = details.proxyInfo; // Firefox only.
|
||||||
if (!proxyInfo || proxyInfo.type === "direct") return null;
|
if (!proxyInfo || proxyInfo.type === "DIRECT") return null;
|
||||||
return getUrlFromProxyInfo(proxyInfo);
|
return getUrlFromProxyInfo(proxyInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,34 @@
|
|||||||
import { Address6 } from "ip-address";
|
import { Address6 } from "ip-address";
|
||||||
import type { ProxyInfo } from "../../types";
|
import type { ProxyInfo, ProxyScheme } from "../../types";
|
||||||
|
|
||||||
export function getProxyInfoFromUrl(
|
export const proxySchemes: { [key: string]: ProxyScheme } = {
|
||||||
url: string
|
direct: "DIRECT",
|
||||||
): ProxyInfo & { type: "http"; host: string; port: number } {
|
http: "PROXY",
|
||||||
|
https: "HTTPS",
|
||||||
|
socks: "SOCKS",
|
||||||
|
socks4: "SOCKS4",
|
||||||
|
socks5: "SOCKS5",
|
||||||
|
quic: "QUIC",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getProxyInfoFromUrl(url: string) {
|
||||||
|
let protocol = "";
|
||||||
|
if (url.includes("://")) {
|
||||||
|
let [proto, urlWithoutProtocol] = url.split("://");
|
||||||
|
protocol = proto;
|
||||||
|
url = urlWithoutProtocol;
|
||||||
|
}
|
||||||
const lastIndexOfAt = url.lastIndexOf("@");
|
const lastIndexOfAt = url.lastIndexOf("@");
|
||||||
const 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) {
|
||||||
host = hostname;
|
host = hostname;
|
||||||
|
if (!protocol) {
|
||||||
port = 3128; // Default port
|
port = 3128; // Default port
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
host = hostname.substring(0, lastIndexOfColon);
|
host = hostname.substring(0, lastIndexOfColon);
|
||||||
port = Number(hostname.substring(lastIndexOfColon + 1, hostname.length));
|
port = Number(hostname.substring(lastIndexOfColon + 1, hostname.length));
|
||||||
@ -31,7 +47,8 @@ export function getProxyInfoFromUrl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "http",
|
type: proxySchemes[protocol] ?? "PROXY",
|
||||||
|
protocol,
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
username,
|
username,
|
||||||
|
@ -92,7 +92,7 @@ function getProxyInfoStringFromUrls(urls: string[]): string {
|
|||||||
return [
|
return [
|
||||||
...urls.map(url => {
|
...urls.map(url => {
|
||||||
const proxyInfo = getProxyInfoFromUrl(url);
|
const proxyInfo = getProxyInfoFromUrl(url);
|
||||||
return `PROXY ${getUrlFromProxyInfo({
|
return `${proxyInfo.type} ${getUrlFromProxyInfo({
|
||||||
...proxyInfo,
|
...proxyInfo,
|
||||||
// Don't include username/password in PAC script.
|
// Don't include username/password in PAC script.
|
||||||
username: undefined,
|
username: undefined,
|
||||||
|
@ -16,10 +16,9 @@ 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 { KeyOfType, ProxyRequestType } from "../types";
|
import { AllowedResult, 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 = {
|
||||||
@ -323,12 +322,16 @@ function isOptimizedProxyUrlAllowed(url: string): AllowedResult {
|
|||||||
return [false, "TTV LOL PRO v1 proxies are not compatible"];
|
return [false, "TTV LOL PRO v1 proxies are not compatible"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/^https?:\/\//i.test(url)) {
|
const proxyInfo = getProxyInfoFromUrl(url);
|
||||||
return [false, "Proxy URLs must not contain a protocol (e.g. 'http://')"];
|
if (proxyInfo.host.includes("/")) {
|
||||||
|
return [false, "Proxy URLs must not contain a path (e.g. '/path')"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.includes("/")) {
|
try {
|
||||||
return [false, "Proxy URLs must not contain a path (e.g. '/path')"];
|
const host = url.substring(url.lastIndexOf("@") + 1, url.length);
|
||||||
|
new URL(`http://${host}`); // Throws if the host is invalid.
|
||||||
|
} catch {
|
||||||
|
return [false, `'${url}' is not a valid proxy URL`];
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
14
src/types.ts
14
src/types.ts
@ -3,9 +3,21 @@ 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
|
||||||
|
export type ProxyScheme =
|
||||||
|
| "DIRECT"
|
||||||
|
| "PROXY"
|
||||||
|
| "HTTPS"
|
||||||
|
| "SOCKS"
|
||||||
|
| "SOCKS4"
|
||||||
|
| "SOCKS5"
|
||||||
|
| "QUIC";
|
||||||
|
|
||||||
// From https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/proxy/ProxyInfo
|
// From https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/proxy/ProxyInfo
|
||||||
export interface ProxyInfo {
|
export interface ProxyInfo {
|
||||||
type: "direct" | "http" | "https" | "socks" | "socks4";
|
type: ProxyScheme;
|
||||||
host?: string;
|
host?: string;
|
||||||
port?: number;
|
port?: number;
|
||||||
username?: string;
|
username?: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user