Spaces:
Paused
Paused
Download src/proxy/captcha-worker-entry.ts from bolikoto/zcode-daili: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/bolikoto/zcode-daili/resolve/main/src/proxy/captcha-worker-entry.ts
- Command line
-
hf download hf://spaces/bolikoto/zcode-daili/src/proxy/captcha-worker-entry.ts
-
curl -L -o captcha-worker-entry.ts https://huggingface.co/spaces/bolikoto/zcode-daili/resolve/main/src/proxy/captcha-worker-entry.ts
1.33 kB
| /** | |
| * Captcha solver worker entry. | |
| * | |
| * Runs the happy-dom solver (captcha-happy.ts) inside a worker thread so the | |
| * proxy's main event loop NEVER blocks on Atomics.wait sync XHRs. One solve | |
| * per worker at a time: the module's global browser-frame/cookie state is | |
| * per-worker, which also removes the cross-solve global races of in-process | |
| * parallel solving. | |
| * | |
| * Protocol: {id, scene, region, prefix} in -> {id, ok, param|error} out. | |
| * Spawned by captcha-worker-dispatch.ts via the captcha-worker-asset.ts | |
| * file asset (`with { type: "file" }`) -- the only worker mechanism that | |
| * survives `bun build --compile` single-file binaries (verified on Bun 1.4). | |
| */ | |
| import { parentPort } from "node:worker_threads"; | |
| import { solveTraceless } from "./captcha-happy.js"; | |
| type SolveMsg = { id: number; scene: string; region: string; prefix: string }; | |
| const port = parentPort; | |
| if (!port) throw new Error("captcha worker entry requires a worker_threads parent"); | |
| port.on("message", (m: SolveMsg) => { | |
| void (async () => { | |
| try { | |
| const param = await solveTraceless({ scene: m.scene, region: m.region, prefix: m.prefix }); | |
| port.postMessage({ id: m.id, ok: true, param }); | |
| } catch (err) { | |
| port.postMessage({ id: m.id, ok: false, error: String((err as Error)?.message ?? err) }); | |
| } | |
| })(); | |
| }); | |