rsshub
Version:
Make RSS Great Again!
96 lines (94 loc) • 3.56 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/e-hentai/index.ts
init_esm_shims();
const route = {
path: "/:what?/:id?/:needTorrents?/:needImages?",
name: "Unknown",
maintainers: [],
features: { nsfw: true },
handler
};
async function handler(ctx) {
const id = ctx.req.param("id") ?? "";
const what = ctx.req.param("what") ?? "";
const needTorrents = /t|y/i.test(ctx.req.param("needTorrents") ?? "true");
const needImages = /t|y/i.test(ctx.req.param("needImages") ?? "true");
const currentUrl = `https://e-hentai.org/${id ? what === "search" ? `?${id}` : what === "category" ? id : `${what}/${id}` : what}`;
const $ = load((await got_default({
method: "get",
url: currentUrl
})).data);
$(".itd").parent().remove();
let items = $("table.gltc tbody tr").slice(1, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) + 1 : needImages ? 16 : 26).toArray().map((item) => {
item = $(item);
return {
title: item.find("div.glink").text(),
author: item.find("td.glhide div a").text(),
link: item.find("td.glname a").attr("href"),
pubDate: parseDate(item.find("div.ir").prev().text()),
category: item.find("div.gt").toArray().map((tag) => $(tag).attr("title").replace(/^:/, "")),
description: needImages ? "" : `<img src="${item.find("div.glthumb div img").attr("data-src") ?? item.find("div.glthumb div img").attr("src")}">`,
enclosure_url: needTorrents ? item.find("div.gldown a img[title=\"Show torrents\"]").length > 0 ? item.find(".gldown a").attr("href") : void 0 : void 0
};
});
items = await Promise.all(items.map(async (item) => {
if (item.enclosure_url) {
let forms = "", torrents = await cache_default.get(item.enclosure_url);
if (!torrents) {
const torrent = load((await got_default({
method: "get",
url: item.enclosure_url
})).data);
torrent("h1, input[name=\"torrent_info\"]").remove();
forms = torrent("form").parent().html();
torrents = torrent("table tbody tr td a").toArray().map((t) => {
t = torrent(t);
return {
link: t.attr("href"),
title: t.text()
};
});
cache_default.set(item.enclosure_url, torrents);
}
item.description += forms;
item.enclosure_url = torrents[0].link;
item.enclosure_type = "application/x-bittorrent";
}
if (needImages) {
let images = await cache_default.get(item.link);
if (!images) {
const content = load((await got_default({
method: "get",
url: item.link
})).data);
images = await Promise.all(content(".gdtm a").toArray().map((i) => cache_default.tryGet(content(i).attr("href"), async () => {
return load((await got_default({
method: "get",
url: content(i).attr("href")
})).data)("#img").attr("src");
})));
cache_default.set(item.link, images);
}
item.description += art(path.join(__dirname, "templates/images-c6c5dab2.art"), { images });
}
return item;
}));
return {
title: `${id || what || "Front Page"} - E-Hentai Galleries`,
link: currentUrl,
item: items
};
}
//#endregion
export { route };