You are an advanced o1 engineer designed to analyze files… · The Chat Archive
Explore You are an advanced o1 engineer designed to analyze files and provide edit instructions… Save Share Download ▾ ReportYou are an advanced o1 engineer designed to analyze files and provide edit instructions based on user requests. Your task is to:
Understand the User Request: Carefully interpret what the user wants to achieve with the modification.
Analyze the File(s): Review the content of the provided file(s).
Generate Edit Instructions: Provide clear, step-by-step instructions on how to modify the file(s) to address the user's request.
Your response should be in the following format:
File: [file_path]
Instructions:
1. [First edit instruction]
2. [Second edit instruction]
...
File: [another_file_path]
Instructions:
1. [First edit instruction]
2. [Second edit instruction]
...
Only provide instructions for files that need changes. Be specific and clear in your instructions.
User request: Added files:
File: index.ts
Content:
import { checkProxyArchive } from "./providers/checkerProxyArchive";
import { github } from "./providers/github";
import * as fs from "fs";
import http from "http";
import path from "path";
import { Worker, isMainThread, parentPort, workerData } from "worker_threads";
import { Elysia } from "elysia";
import cp from "child_process";
let proxies: string[];
async function scrapeProxies() {
const [one, two] = await Promise.all([checkProxyArchive(), github()]);
proxies = [...one, ...two];
proxies = [...new Set(proxies)];
fs.writeFileSync("proxies.txt", proxies.join("\n"));
console.log(Scraped ${proxies.length.toLocaleString("en-US")} proxy(ies));
}
const dataPath = "data.json";
if (!fs.existsSync(dataPath)) {
fs.writeFileSync(dataPath, JSON.stringify({ lastScrape: "" }));
}
const data = JSON.parse(fs.readFileSync(dataPath, "utf8"));
if (data.lastScrape === "" || Date.now() - data.lastScrape > 10 * 60 * 1000) {
scrapeProxies();
fs.writeFileSync(dataPath, JSON.stringify({ lastScrape: Date.now() }));
} else {
proxies = fs.readFileSync("proxies.txt", "utf8").split("\n");
proxies = [...new Set(proxies)];
console.log(Loaded ${proxies.length.toLocaleString("en-US")} proxy(ies));
fs.writeFileSync("proxies.txt", proxies.join("\n"));
}
const app = new Elysia();
app.get("/getProxy", () => {
const workingProxiesPath = "working_proxies.json";
if (!fs.existsSync(workingProxiesPath)) {
fs.writeFileSync(workingProxiesPath, JSON.stringify({}));
}
const workingProxies = JSON.parse(
fs.readFileSync(workingProxiesPath, "utf8")
);
const recentProxies = Object.entries(workingProxies).filter(
([_, data]: [string, any]) => Date.now() - data.lastChecked < 60 * 1000
);
if (recentProxies.length === 0) {
return null;
}
const [selectedProxy] =
recentProxies[Math.floor(Math.random() * recentProxies.length)];
return selectedProxy;
});
Assistant2024-10-09 13:09 UTC Copy response
File: index.ts
Instructions:
1. Add debug log at the beginning of `scrapeProxies` to indicate the scraping process's start:
```ts
console.log("Starting proxy scraping...");
Place this line just before the line
Copy first prompt
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 1 (2 messages)
Language en
Conversation date Oct 9, 2024
Added to archive Nov 16, 2026
ID 01m7h41x6fcv9bkbbx7caewn6nSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 41df2026ee9b4821df593613b79cf484
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
const configPath = path.join(__dirname, "config.json");
interface Config {
Threads: number;
InputFile: string;
MaxTimeout: number;
Hosts: string[];
}
const defaultConfig: Config = {
Threads: 1,
InputFile: "proxies.txt",
MaxTimeout: 1000,
Hosts: ["example.com"],
};
if (!fs.existsSync(configPath)) {
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 4));
}
const config: Config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
let validProxies: string[] = [];
function getRandomHost(): string {
const hosts = config.Hosts;
return hosts[Math.floor(Math.random() * hosts.length)];
}
export async function checkProxy(
proxy: string,
maxTimeout: number
): Promise {
const [host, port] = proxy.split(":");
const targetHost = getRandomHost();
const proxyUrl = http://${host}:${port};
const url = http://${targetHost};
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), maxTimeout);
return new Promise<boolean>((resolve) => {
const curlCommand = `curl "${url}" --proxy "${proxyUrl}" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" -H "Host: ${targetHost}" -o /dev/null -w "%{http_code}"`;
cp.exec(curlCommand, { timeout: maxTimeout }, (error, stdout, stderr) => {
clearTimeout(timeoutId);
if (error) {
resolve(false);
} else {
const statusCode = parseInt(stdout.trim(), 10);
resolve(statusCode === 200);
}
});
});
} catch (error) {
return false;
}
}
async function checkProxyWithTimeout(
proxy: string,
maxTimeout: number
): Promise {
return Promise.race([
checkProxy(proxy, maxTimeout),
new Promise((resolve) =>
setTimeout(() => resolve(false), maxTimeout)
),
]);
}
async function workerFunction({
proxies,
maxTimeout,
}: {
proxies: string[];
maxTimeout: number;
}): Promise {
const results: string[] = [];
const workingProxiesPath = "working_proxies.json";
for (const proxy of proxies) {
const isValid = await checkProxyWithTimeout(proxy, maxTimeout);
if (isValid) {
console.log(\x1b[32m[+] ${proxy}\x1b[0m);
results.push(proxy);
// update working_proxies.json
let workingProxies: { [key: string]: { lastChecked: number } } = {};
if (fs.existsSync(workingProxiesPath)) {
try {
const fileContent = fs.readFileSync(workingProxiesPath, "utf8");
workingProxies = JSON.parse(fileContent);
} catch (error) {
console.error("Error parsing working_proxies.json:", error);
}
}
workingProxies[proxy] = { lastChecked: Date.now() };
fs.writeFileSync(
workingProxiesPath,
JSON.stringify(workingProxies, null, 4)
);
} else {
// console.log(\x1b[31m[-] ${proxy}\x1b[0m);
}
}
parentPort?.postMessage(results);
}
if (isMainThread) {
async function scrapeAndCheckProxies(): Promise {
// Clear working_proxies.json before restarting
const workingProxiesPath = "working_proxies.json";
fs.writeFileSync(workingProxiesPath, JSON.stringify({}));
console.log("Cleared working_proxies.json");
await scrapeProxies();
const proxies = fs
.readFileSync(config.InputFile, "utf-8")
.split("\n")
.filter(Boolean);
const chunkSize = Math.ceil(proxies.length / config.Threads);
const threads: Promise<void>[] = [];
for (let i = 0; i < config.Threads; i++) {
const chunk = proxies.slice(i * chunkSize, (i + 1) * chunkSize);
threads.push(
new Promise((resolve, reject) => {
const worker = new Worker(__filename, {
workerData: { proxies: chunk, maxTimeout: config.MaxTimeout },
});
worker.on("message", (message: string[]) => {
validProxies = validProxies.concat(message);
resolve();
});
worker.on("error", reject);
worker.on("exit", (code: number) => {
if (code !== 0)
reject(new Error(`Worker stopped with exit code ${code}`));
});
})
);
}
await Promise.all(threads);
console.log(`Finished checking proxies!`);
async function main(): Promise {
while (true) {
await scrapeAndCheckProxies();
console.log("Waiting before next cycle...");
await new Promise((resolve) => setTimeout(resolve, 60000)); // Wait for 1 minute
}
}
process.on("SIGINT", () => {
console.log("\nGracefully shutting down...");
console.log(Checked proxies didn't save!);
process.exit();
});
main();
} else {
workerFunction(workerData as { proxies: string[]; maxTimeout: number });
}
File: index.ts
Content:
import { checkProxyArchive } from "./providers/checkerProxyArchive";
import { github } from "./providers/github";
import * as fs from "fs";
import http from "http";
import path from "path";
import { Worker, isMainThread, parentPort, workerData } from "worker_threads";
import { Elysia } from "elysia";
import cp from "child_process";
async function scrapeProxies() {
const [one, two] = await Promise.all([checkProxyArchive(), github()]);
proxies = [...one, ...two];
proxies = [...new Set(proxies)];
fs.writeFileSync("proxies.txt", proxies.join("\n"));
console.log(Scraped ${proxies.length.toLocaleString("en-US")} proxy(ies));
}
const dataPath = "data.json";
if (!fs.existsSync(dataPath)) {
fs.writeFileSync(dataPath, JSON.stringify({ lastScrape: "" }));
}
const data = JSON.parse(fs.readFileSync(dataPath, "utf8"));
if (data.lastScrape === "" || Date.now() - data.lastScrape > 10 * 60 * 1000) {
scrapeProxies();
fs.writeFileSync(dataPath, JSON.stringify({ lastScrape: Date.now() }));
} else {
proxies = fs.readFileSync("proxies.txt", "utf8").split("\n");
proxies = [...new Set(proxies)];
console.log(Loaded ${proxies.length.toLocaleString("en-US")} proxy(ies));
fs.writeFileSync("proxies.txt", proxies.join("\n"));
}
const app = new Elysia();
app.get("/getProxy", () => {
const workingProxiesPath = "working_proxies.json";
if (!fs.existsSync(workingProxiesPath)) {
fs.writeFileSync(workingProxiesPath, JSON.stringify({}));
}
const workingProxies = JSON.parse(
fs.readFileSync(workingProxiesPath, "utf8")
);
const recentProxies = Object.entries(workingProxies).filter(
([_, data]: [string, any]) => Date.now() - data.lastChecked < 60 * 1000
);
if (recentProxies.length === 0) {
return null;
}
const [selectedProxy] =
recentProxies[Math.floor(Math.random() * recentProxies.length)];
return selectedProxy;
});
const configPath = path.join(__dirname, "config.json");
interface Config {
Threads: number;
InputFile: string;
MaxTimeout: number;
Hosts: string[];
}
const defaultConfig: Config = {
Threads: 1,
InputFile: "proxies.txt",
MaxTimeout: 1000,
Hosts: ["example.com"],
};
if (!fs.existsSync(configPath)) {
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 4));
}
const config: Config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
let validProxies: string[] = [];
function getRandomHost(): string {
const hosts = config.Hosts;
return hosts[Math.floor(Math.random() * hosts.length)];
}
export async function checkProxy(
proxy: string,
maxTimeout: number
): Promise {
const [host, port] = proxy.split(":");
const targetHost = getRandomHost();
const proxyUrl = http://${host}:${port};
const url = http://${targetHost};
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), maxTimeout);
return new Promise<boolean>((resolve) => {
const curlCommand = `curl "${url}" --proxy "${proxyUrl}" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" -H "Host: ${targetHost}" -o /dev/null -w "%{http_code}"`;
cp.exec(curlCommand, { timeout: maxTimeout }, (error, stdout, stderr) => {
clearTimeout(timeoutId);
if (error) {
resolve(false);
} else {
const statusCode = parseInt(stdout.trim(), 10);
resolve(statusCode === 200);
}
});
});
} catch (error) {
return false;
}
}
async function checkProxyWithTimeout(
proxy: string,
maxTimeout: number
): Promise {
return Promise.race([
checkProxy(proxy, maxTimeout),
new Promise((resolve) =>
setTimeout(() => resolve(false), maxTimeout)
),
]);
}
async function workerFunction({
proxies,
maxTimeout,
}: {
proxies: string[];
maxTimeout: number;
}): Promise {
const results: string[] = [];
const workingProxiesPath = "working_proxies.json";
for (const proxy of proxies) {
const isValid = await checkProxyWithTimeout(proxy, maxTimeout);
if (isValid) {
console.log(\x1b[32m[+] ${proxy}\x1b[0m);
results.push(proxy);
// update working_proxies.json
let workingProxies: { [key: string]: { lastChecked: number } } = {};
if (fs.existsSync(workingProxiesPath)) {
try {
const fileContent = fs.readFileSync(workingProxiesPath, "utf8");
workingProxies = JSON.parse(fileContent);
} catch (error) {
console.error("Error parsing working_proxies.json:", error);
}
}
workingProxies[proxy] = { lastChecked: Date.now() };
fs.writeFileSync(
workingProxiesPath,
JSON.stringify(workingProxies, null, 4)
);
} else {
// console.log(\x1b[31m[-] ${proxy}\x1b[0m);
}
}
parentPort?.postMessage(results);
}
if (isMainThread) {
async function scrapeAndCheckProxies(): Promise {
// Clear working_proxies.json before restarting
const workingProxiesPath = "working_proxies.json";
fs.writeFileSync(workingProxiesPath, JSON.stringify({}));
console.log("Cleared working_proxies.json");
await scrapeProxies();
const proxies = fs
.readFileSync(config.InputFile, "utf-8")
.split("\n")
.filter(Boolean);
const chunkSize = Math.ceil(proxies.length / config.Threads);
const threads: Promise<void>[] = [];
for (let i = 0; i < config.Threads; i++) {
const chunk = proxies.slice(i * chunkSize, (i + 1) * chunkSize);
threads.push(
new Promise((resolve, reject) => {
const worker = new Worker(__filename, {
workerData: { proxies: chunk, maxTimeout: config.MaxTimeout },
});
worker.on("message", (message: string[]) => {
validProxies = validProxies.concat(message);
resolve();
});
worker.on("error", reject);
worker.on("exit", (code: number) => {
if (code !== 0)
reject(new Error(`Worker stopped with exit code ${code}`));
});
})
);
}
await Promise.all(threads);
console.log(`Finished checking proxies!`);
async function main(): Promise {
while (true) {
await scrapeAndCheckProxies();
console.log("Waiting before next cycle...");
await new Promise((resolve) => setTimeout(resolve, 60000)); // Wait for 1 minute
}
}
process.on("SIGINT", () => {
console.log("\nGracefully shutting down...");
console.log(Checked proxies didn't save!);
process.exit();
});
main();
} else {
workerFunction(workerData as { proxies: string[]; maxTimeout: number });
}
PROMPT: You are an advanced o1 engineer designed to analyze files and provide edit instructions based on user requests. Your task is to:
Understand the User Request: Carefully interpret what the user wants to achieve with the modification.
Analyze the File(s): Review the content of the provided file(s).
Generate Edit Instructions: Provide clear, step-by-step instructions on how to modify the file(s) to address the user's request.
Your response should be in the following format:
File: [file_path]
Instructions:
1. [First edit instruction]
2. [Second edit instruction]
...
File: [another_file_path]
Instructions:
1. [First edit instruction]
2. [Second edit instruction]
...
Only provide instructions for files that need changes. Be specific and clear in your instructions.
User request: Added files:
File: index.ts
Content:
import { checkProxyArchive } from "./providers/checkerProxyArchive";
import { github } from "./providers/github";
import * as fs from "fs";
import http from "http";
import path from "path";
import { Worker, isMainThread, parentPort, workerData } from "worker_threads";
import { Elysia } from "elysia";
import cp from "child_process";
async function scrapeProxies() {
const [one, two] = await Promise.all([checkProxyArchive(), github()]);
proxies = [...one, ...two];
proxies = [...new Set(proxies)];
fs.writeFileSync("proxies.txt", proxies.join("\n"));
console.log(Scraped ${proxies.length.toLocaleString("en-US")} proxy(ies));
}
const dataPath = "data.json";
if (!fs.existsSync(dataPath)) {
fs.writeFileSync(dataPath, JSON.stringify({ lastScrape: "" }));
}
const data = JSON.parse(fs.readFileSync(dataPath, "utf8"));
if (data.lastScrape === "" || Date.now() - data.lastScrape > 10 * 60 * 1000) {
scrapeProxies();
fs.writeFileSync(dataPath, JSON.stringify({ lastScrape: Date.now() }));
} else {
proxies = fs.readFileSync("proxies.txt", "utf8").split("\n");
proxies = [...new Set(proxies)];
console.log(Loaded ${proxies.length.toLocaleString("en-US")} proxy(ies));
fs.writeFileSync("proxies.txt", proxies.join("\n"));
}
const app = new Elysia();
app.get("/getProxy", () => {
const workingProxiesPath = "working_proxies.json";
if (!fs.existsSync(workingProxiesPath)) {
fs.writeFileSync(workingProxiesPath, JSON.stringify({}));
}
const workingProxies = JSON.parse(
fs.readFileSync(workingProxiesPath, "utf8")
);
const recentProxies = Object.entries(workingProxies).filter(
([_, data]: [string, any]) => Date.now() - data.lastChecked < 60 * 1000
);
if (recentProxies.length === 0) {
return null;
}
const [selectedProxy] =
recentProxies[Math.floor(Math.random() * recentProxies.length)];
return selectedProxy;
});
const configPath = path.join(__dirname, "config.json");
interface Config {
Threads: number;
InputFile: string;
MaxTimeout: number;
Hosts: string[];
}
const defaultConfig: Config = {
Threads: 1,
InputFile: "proxies.txt",
MaxTimeout: 1000,
Hosts: ["example.com"],
};
if (!fs.existsSync(configPath)) {
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 4));
}
const config: Config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
let validProxies: string[] = [];
function getRandomHost(): string {
const hosts = config.Hosts;
return hosts[Math.floor(Math.random() * hosts.length)];
}
export async function checkProxy(
proxy: string,
maxTimeout: number
): Promise {
const [host, port] = proxy.split(":");
const targetHost = getRandomHost();
const proxyUrl = http://${host}:${port};
const url = http://${targetHost};
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), maxTimeout);
return new Promise<boolean>((resolve) => {
const curlCommand = `curl "${url}" --proxy "${proxyUrl}" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" -H "Host: ${targetHost}" -o /dev/null -w "%{http_code}"`;
cp.exec(curlCommand, { timeout: maxTimeout }, (error, stdout, stderr) => {
clearTimeout(timeoutId);
if (error) {
resolve(false);
} else {
const statusCode = parseInt(stdout.trim(), 10);
resolve(statusCode === 200);
}
});
});
} catch (error) {
return false;
}
}
async function checkProxyWithTimeout(
proxy: string,
maxTimeout: number
): Promise {
return Promise.race([
checkProxy(proxy, maxTimeout),
new Promise((resolve) =>
setTimeout(() => resolve(false), maxTimeout)
),
]);
}
async function workerFunction({
proxies,
maxTimeout,
}: {
proxies: string[];
maxTimeout: number;
}): Promise {
const results: string[] = [];
const workingProxiesPath = "working_proxies.json";
for (const proxy of proxies) {
const isValid = await checkProxyWithTimeout(proxy, maxTimeout);
if (isValid) {
console.log(\x1b[32m[+] ${proxy}\x1b[0m);
results.push(proxy);
// update working_proxies.json
let workingProxies: { [key: string]: { lastChecked: number } } = {};
if (fs.existsSync(workingProxiesPath)) {
try {
const fileContent = fs.readFileSync(workingProxiesPath, "utf8");
workingProxies = JSON.parse(fileContent);
} catch (error) {
console.error("Error parsing working_proxies.json:", error);
}
}
workingProxies[proxy] = { lastChecked: Date.now() };
fs.writeFileSync(
workingProxiesPath,
JSON.stringify(workingProxies, null, 4)
);
} else {
// console.log(\x1b[31m[-] ${proxy}\x1b[0m);
}
}
parentPort?.postMessage(results);
}
if (isMainThread) {
async function scrapeAndCheckProxies(): Promise {
// Clear working_proxies.json before restarting
const workingProxiesPath = "working_proxies.json";
fs.writeFileSync(workingProxiesPath, JSON.stringify({}));
console.log("Cleared working_proxies.json");
await scrapeProxies();
const proxies = fs
.readFileSync(config.InputFile, "utf-8")
.split("\n")
.filter(Boolean);
const chunkSize = Math.ceil(proxies.length / config.Threads);
const threads: Promise<void>[] = [];
for (let i = 0; i < config.Threads; i++) {
const chunk = proxies.slice(i * chunkSize, (i + 1) * chunkSize);
threads.push(
new Promise((resolve, reject) => {
const worker = new Worker(__filename, {
workerData: { proxies: chunk, maxTimeout: config.MaxTimeout },
});
worker.on("message", (message: string[]) => {
validProxies = validProxies.concat(message);
resolve();
});
worker.on("error", reject);
worker.on("exit", (code: number) => {
if (code !== 0)
reject(new Error(`Worker stopped with exit code ${code}`));
});
})
);
}
await Promise.all(threads);
console.log(`Finished checking proxies!`);
async function main(): Promise {
while (true) {
await scrapeAndCheckProxies();
console.log("Waiting before next cycle...");
await new Promise((resolve) => setTimeout(resolve, 60000)); // Wait for 1 minute
}
}
process.on("SIGINT", () => {
console.log("\nGracefully shutting down...");
console.log(Checked proxies didn't save!);
process.exit();
});
main();
} else {
workerFunction(workerData as { proxies: string[]; maxTimeout: number });
}
File: index.ts
Content:
import { checkProxyArchive } from "./providers/checkerProxyArchive";
import { github } from "./providers/github";
import * as fs from "fs";
import http from "http";
import path from "path";
import { Worker, isMainThread, parentPort, workerData } from "worker_threads";
import { Elysia } from "elysia";
import cp from "child_process";
async function scrapeProxies() {
const [one, two] = await Promise.all([checkProxyArchive(), github()]);
proxies = [...one, ...two];
proxies = [...new Set(proxies)];
fs.writeFileSync("proxies.txt", proxies.join("\n"));
console.log(Scraped ${proxies.length.toLocaleString("en-US")} proxy(ies));
}
const dataPath = "data.json";
if (!fs.existsSync(dataPath)) {
fs.writeFileSync(dataPath, JSON.stringify({ lastScrape: "" }));
}
const data = JSON.parse(fs.readFileSync(dataPath, "utf8"));
if (data.lastScrape === "" || Date.now() - data.lastScrape > 10 * 60 * 1000) {
scrapeProxies();
fs.writeFileSync(dataPath, JSON.stringify({ lastScrape: Date.now() }));
} else {
proxies = fs.readFileSync("proxies.txt", "utf8").split("\n");
proxies = [...new Set(proxies)];
console.log(Loaded ${proxies.length.toLocaleString("en-US")} proxy(ies));
fs.writeFileSync("proxies.txt", proxies.join("\n"));
}
const app = new Elysia();
app.get("/getProxy", () => {
const workingProxiesPath = "working_proxies.json";
if (!fs.existsSync(workingProxiesPath)) {
fs.writeFileSync(workingProxiesPath, JSON.stringify({}));
}
const workingProxies = JSON.parse(
fs.readFileSync(workingProxiesPath, "utf8")
);
const recentProxies = Object.entries(workingProxies).filter(
([_, data]: [string, any]) => Date.now() - data.lastChecked < 60 * 1000
);
if (recentProxies.length === 0) {
return null;
}
const [selectedProxy] =
recentProxies[Math.floor(Math.random() * recentProxies.length)];
return selectedProxy;
});
const configPath = path.join(__dirname, "config.json");
interface Config {
Threads: number;
InputFile: string;
MaxTimeout: number;
Hosts: string[];
}
const defaultConfig: Config = {
Threads: 1,
InputFile: "proxies.txt",
MaxTimeout: 1000,
Hosts: ["example.com"],
};
if (!fs.existsSync(configPath)) {
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 4));
}
const config: Config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
let validProxies: string[] = [];
function getRandomHost(): string {
const hosts = config.Hosts;
return hosts[Math.floor(Math.random() * hosts.length)];
}
export async function checkProxy(
proxy: string,
maxTimeout: number
): Promise {
const [host, port] = proxy.split(":");
const targetHost = getRandomHost();
const proxyUrl = http://${host}:${port};
const url = http://${targetHost};
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), maxTimeout);
return new Promise<boolean>((resolve) => {
const curlCommand = `curl "${url}" --proxy "${proxyUrl}" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" -H "Host: ${targetHost}" -o /dev/null -w "%{http_code}"`;
cp.exec(curlCommand, { timeout: maxTimeout }, (error, stdout, stderr) => {
clearTimeout(timeoutId);
if (error) {
resolve(false);
} else {
const statusCode = parseInt(stdout.trim(), 10);
resolve(statusCode === 200);
}
});
});
} catch (error) {
return false;
}
}
async function checkProxyWithTimeout(
proxy: string,
maxTimeout: number
): Promise {
return Promise.race([
checkProxy(proxy, maxTimeout),
new Promise((resolve) =>
setTimeout(() => resolve(false), maxTimeout)
),
]);
}
async function workerFunction({
proxies,
maxTimeout,
}: {
proxies: string[];
maxTimeout: number;
}): Promise {
const results: string[] = [];
const workingProxiesPath = "working_proxies.json";
for (const proxy of proxies) {
const isValid = await checkProxyWithTimeout(proxy, maxTimeout);
if (isValid) {
console.log(\x1b[32m[+] ${proxy}\x1b[0m);
results.push(proxy);
// update working_proxies.json
let workingProxies: { [key: string]: { lastChecked: number } } = {};
if (fs.existsSync(workingProxiesPath)) {
try {
const fileContent = fs.readFileSync(workingProxiesPath, "utf8");
workingProxies = JSON.parse(fileContent);
} catch (error) {
console.error("Error parsing working_proxies.json:", error);
}
}
workingProxies[proxy] = { lastChecked: Date.now() };
fs.writeFileSync(
workingProxiesPath,
JSON.stringify(workingProxies, null, 4)
);
} else {
// console.log(\x1b[31m[-] ${proxy}\x1b[0m);
}
}
parentPort?.postMessage(results);
}
if (isMainThread) {
async function scrapeAndCheckProxies(): Promise {
// Clear working_proxies.json before restarting
const workingProxiesPath = "working_proxies.json";
fs.writeFileSync(workingProxiesPath, JSON.stringify({}));
console.log("Cleared working_proxies.json");
await scrapeProxies();
const proxies = fs
.readFileSync(config.InputFile, "utf-8")
.split("\n")
.filter(Boolean);
const chunkSize = Math.ceil(proxies.length / config.Threads);
const threads: Promise<void>[] = [];
for (let i = 0; i < config.Threads; i++) {
const chunk = proxies.slice(i * chunkSize, (i + 1) * chunkSize);
threads.push(
new Promise((resolve, reject) => {
const worker = new Worker(__filename, {
workerData: { proxies: chunk, maxTimeout: config.MaxTimeout },
});
worker.on("message", (message: string[]) => {
validProxies = validProxies.concat(message);
resolve();
});
worker.on("error", reject);
worker.on("exit", (code: number) => {
if (code !== 0)
reject(new Error(`Worker stopped with exit code ${code}`));
});
})
);
}
await Promise.all(threads);
console.log(`Finished checking proxies!`);
async function main(): Promise {
while (true) {
await scrapeAndCheckProxies();
console.log("Waiting before next cycle...");
await new Promise((resolve) => setTimeout(resolve, 60000)); // Wait for 1 minute
}
}
process.on("SIGINT", () => {
console.log("\nGracefully shutting down...");
console.log(Checked proxies didn't save!);
process.exit();
});
main();
} else {
workerFunction(workerData as { proxies: string[]; maxTimeout: number });
}
const [one, two] = await Promise.all([checkProxyArchive(), github()]);
Add a debug log after fetching proxies from the sources in scrapeProxies to see how many proxies are fetched from each source:
console.log(`Fetched ${one.length} proxies from checkProxyArchive and ${two.length} proxies from github.`);
Place this line after the line const [one, two] = await Promise.all([checkProxyArchive(), github()]);
Add debug log before writing to proxies.txt in scrapeProxies to confirm the number of unique proxies:
console.log(`Writing ${proxies.length} unique proxies to proxies.txt...`);
Place this line before fs.writeFileSync("proxies.txt", proxies.join("\n"));
In checkProxy, log the curl command being executed for debugging purposes:
console.log(`Executing command: ${curlCommand}`);
Place this line just before cp.exec(curlCommand, { timeout: maxTimeout }, (error, stdout, stderr) => {...}
Upon checking the proxy validity in checkProxyWithTimeout, add debug logs to view the result:
console.log(`Proxy ${proxy} validation result: ${isValid}`);
Place this line just after const isValid = await checkProxyWithTimeout(proxy, maxTimeout); in workerFunction
Before clearing working_proxies.json in scrapeAndCheckProxies, log this action for tracking:
console.log("Clearing working_proxies.json...");
Place this line just before fs.writeFileSync(workingProxiesPath, JSON.stringify({}));
Add a debug log at the start of the main function to indicate the beginning of the main loop process:
console.log("Starting main loop...");
Place this log after starting the main function.
Inside main, after waiting before the next cycle, add a log indicating the wait is complete:
console.log("1 minute wait over, restarting the proxy check cycle...");
Place this log after the wait line (await new Promise((resolve) => setTimeout(resolve, 60000));)
Copy first response
Not yet included in a published release.