Buckets:
| import { readFileSync, existsSync } from "node:fs"; | |
| export type Proxy = { | |
| host: string; | |
| port: number; | |
| username?: string; | |
| password?: string; | |
| }; | |
| let proxies: Proxy[] = []; | |
| let currentIndex = 0; | |
| function parseLine(line: string): Proxy | null { | |
| const trimmed = line.trim(); | |
| if (!trimmed || trimmed.startsWith("#")) return null; | |
| const parts = trimmed.split(":"); | |
| if (parts.length === 2) { | |
| return { host: parts[0], port: parseInt(parts[1], 10) }; | |
| } | |
| if (parts.length >= 4) { | |
| return { | |
| host: parts[0], | |
| port: parseInt(parts[1], 10), | |
| username: parts[2], | |
| password: parts.slice(3).join(":"), | |
| }; | |
| } | |
| return null; | |
| } | |
| export function loadProxies(): number { | |
| const path = process.env.PROXIES_FILE; | |
| if (!path || !existsSync(path)) { | |
| proxies = []; | |
| return 0; | |
| } | |
| proxies = readFileSync(path, "utf-8") | |
| .split(/\r?\n/) | |
| .map(parseLine) | |
| .filter((p): p is Proxy => p !== null); | |
| return proxies.length; | |
| } | |
| export function getNextProxy(): Proxy | null { | |
| if (proxies.length === 0) return null; | |
| const proxy = proxies[currentIndex % proxies.length]; | |
| currentIndex++; | |
| return proxy; | |
| } | |
| export function hasProxies(): boolean { | |
| return proxies.length > 0; | |
| } | |
| export function formatProxyUrl(proxy: Proxy): string { | |
| if (proxy.username && proxy.password) { | |
| return `http://${encodeURIComponent(proxy.username)}:${encodeURIComponent(proxy.password)}@${proxy.host}:${proxy.port}`; | |
| } | |
| return `http://${proxy.host}:${proxy.port}`; | |
| } | |
Xet Storage Details
- Size:
- 1.5 kB
- Xet hash:
- 9a4ffccf5f679fbd0684d42de9d10de4ddef03aefedb519780397eb1efb335a3
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.