4 Commits

Author SHA1 Message Date
SNEK WAIFU
e92cb6ca8a ee 2026-05-14 08:09:23 +07:00
SNEK WAIFU
85a45cf575 eeee 2026-05-14 08:09:04 +07:00
SNEK WAIFU
fe225e1090 8.3.4-alpha 2026-05-14 07:25:26 +07:00
SNEK WAIFU
6ed1567f0e need testing 2026-05-14 07:24:58 +07:00
4 changed files with 41 additions and 11 deletions

3
.gitignore vendored
View File

@@ -10,4 +10,5 @@ p.ts
.idea
CHANGELOG.md
theme.zip
AGENTS.md
AGENTS.md
lustpress-express

View File

@@ -1,6 +1,6 @@
{
"name": "lustpress",
"version": "8.2.4-alpha",
"version": "8.3.5-alpha",
"description": "RESTful and experimental API for PH and other R18 websites",
"main": "src/index.ts",
"scripts": {

View File

@@ -25,12 +25,14 @@ function cachedLocationOrUnknown(): string {
class LustPress {
url: string;
useragent: string;
private browserUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36";
private browserUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36";
private cookieCache: { [domain: string]: string } = {};
constructor() {
this.url = "";
this.useragent = `${pkg.name}/${pkg.version} Bun/${Bun.version}`;
this.browserUA =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36";
this.useragent = process.env.USER_AGENT || `${pkg.name}/${pkg.version} Bun/${Bun.version}`;
}
async getPornhubCookies(): Promise<string> {
@@ -87,6 +89,17 @@ class LustPress {
const headers: Record<string, string> = {
"User-Agent": isPornhub ? this.browserUA : this.useragent,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Language": "en-US,en;q=0.9",
"Accept-Encoding": "gzip, deflate, br",
"Sec-Ch-Ua": '"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1"
};
if (isPornhub) {
@@ -101,20 +114,23 @@ class LustPress {
console.log(`[FETCH] ${url}`);
let res = await fetch(url, { headers, redirect: "follow" });
let text = await res.text();
let arrayBuf = await res.arrayBuffer();
let body = Buffer.from(arrayBuf);
if (isPornhub && text.includes("leastFactor")) {
if (isPornhub && body.toString("utf8").includes("leastFactor")) {
console.log("Challenge detected at target URL. Re-authenticating...");
this.cookieCache[domain] = await this.getPornhubCookies();
res = await fetch(url, {
headers: { ...headers, Cookie: this.cookieCache[domain] },
redirect: "follow"
});
text = await res.text();
arrayBuf = await res.arrayBuffer();
body = Buffer.from(arrayBuf);
}
const body = Buffer.from(text);
if (!url.includes("/random")) await keyv.set(url, body, ttl);
if (res.ok && !url.includes("/random")) {
await keyv.set(url, body, ttl);
}
return body;
}

View File

@@ -30,9 +30,7 @@ const app = new Elysia()
server: await lust.getServer(),
version: pkg.version,
}))
.use(scrapeRoutes)
.onError(({ code, error, set }) => {
console.log("Error occurred:", error);
if (code === "NOT_FOUND") {
set.status = 404;
return {
@@ -40,6 +38,20 @@ const app = new Elysia()
message: (error as Error).message || "Not Found",
};
}
if (code === "VALIDATION") {
set.status = 400;
return {
success: false,
message: JSON.parse((error as Error).message)[0]?.message || "Validation Error",
};
}
if (code === "UNKNOWN") {
set.status = 400;
return {
success: false,
message: (error as Error).message,
};
}
set.status = 500;
return {
success: false,
@@ -47,6 +59,7 @@ const app = new Elysia()
stack: (error as Error).stack,
};
})
.use(scrapeRoutes)
.listen(process.env.PORT || 3000);
console.log(