feat: add Cloudflare bypass to fetchSourceFurnidata using puppeteer
- Add cf-fetch.ts with puppeteer-extra + stealth plugin for CF bypass - Modify fetchSourceFurnidata to detect CF challenge and retry with puppeteer - Restore Leet, Hubbly, and Habblet City to clone sources (now CF-protected)
This commit is contained in:
1 parent
624edf751a
commit
a338f9cb72
3 files changed
+116
-13
No files matched your search
@@ -3,6 +3,7 @@ import path from "node:path";
|
||||
import { eq, inArray, sql } from "drizzle-orm";
|
||||
import { db, ItemsBase } from "@/lib/db";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { fetchWithCfBypass } from "@/lib/services/cf-fetch";
|
||||
import { extractFurniIconPng } from "@/lib/services/clone-icon";
|
||||
import type { CloneSource } from "@/lib/services/clone-sources";
|
||||
import { getFurniAssetDirs } from "@/lib/services/furni-asset-dirs";
|
||||
@@ -88,14 +89,23 @@ export async function fetchSourceFurnidata(
|
||||
): Promise<SourceFurni[]> {
|
||||
const hit = cache.get(url);
|
||||
if (hit && now && now - hit.ts < TTL) return hit.list;
|
||||
const res = await fetch(url, {
|
||||
signal: AbortSignal.timeout(30000),
|
||||
headers: browserHeaders(),
|
||||
});
|
||||
if (!res.ok) throw new Error(`furnidata fetch failed: ${res.status} ${url}`);
|
||||
let body: string;
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
signal: AbortSignal.timeout(30000),
|
||||
headers: browserHeaders(),
|
||||
});
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
const text = await res.text();
|
||||
if (typeof text === "string" && text.trim().startsWith("<"))
|
||||
throw new Error("Cloudflare challenge detected");
|
||||
body = text;
|
||||
} catch {
|
||||
body = await fetchWithCfBypass(url);
|
||||
}
|
||||
let list: SourceFurni[];
|
||||
try {
|
||||
const json = await res.json();
|
||||
const json = JSON.parse(body);
|
||||
list = parseFurnidata(json);
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
|
||||
Reference in new issue
Block a user