repo: init
This commit is contained in:
43
src/proxy/reflect4.ts
Normal file
43
src/proxy/reflect4.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { type BrowserContext, type Locator } from "patchright";
|
||||
import logger from "../logger";
|
||||
import * as twitch from "../website/twitch";
|
||||
import * as constants from "../constants";
|
||||
|
||||
async function spawn(context: BrowserContext, targetUrl: string) {
|
||||
const spawnId = btoa(Math.random().toString()).substring(4,10);
|
||||
const server = constants.REFLECT4_SERVERS[Math.floor(Math.random() * constants.REFLECT4_SERVERS.length)];
|
||||
logger.debug(`[${spawnId}] Using reflect4 server: ${server}`);
|
||||
const page = await context.newPage();
|
||||
await page.goto(server);
|
||||
let targetInput: Locator | null = null;
|
||||
const allInput = await page.locator("input").all();
|
||||
for (const input of allInput) {
|
||||
const placeholder = await input.getAttribute("placeholder");
|
||||
if (placeholder?.includes("URL")) {
|
||||
targetInput = input;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!targetInput) {
|
||||
logger.error(`[${spawnId}] Failed to find input field for URL input`);
|
||||
return;
|
||||
}
|
||||
await targetInput.fill(targetUrl);
|
||||
await targetInput.press("Enter");
|
||||
// Keep-alive the page open for 5 minutes then refresh
|
||||
if (targetUrl.startsWith("https://www.twitch.tv/")) {
|
||||
twitch.keepAlive(page, spawnId);
|
||||
} else {
|
||||
logger.warn(`[${spawnId}] Unsupported URL: ${targetUrl}`);
|
||||
logger.warn(`[${spawnId}] Will try to keep alive, but no guarantees`);
|
||||
while (true) {
|
||||
await page.waitForTimeout(5 * 60 * 1000); // 5 minutes
|
||||
await page.reload();
|
||||
logger.debug(`[${spawnId}] Reloaded page`);
|
||||
}
|
||||
}
|
||||
await page.close();
|
||||
logger.info(`[${spawnId}] Proxy with the server ${server} closed`);
|
||||
}
|
||||
|
||||
export { spawn };
|
||||
Reference in New Issue
Block a user