rsshub
Version:
Make RSS Great Again!
95 lines (93 loc) • 3.84 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 "./md5-C8GRvctM.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import "./got-KxxWdaxq.mjs";
import "./config-not-found-Dyp3RlZZ.mjs";
import { a as getRootUrl, i as getApiUrl, n as apiMapCategory, o as processApiItems, r as defaultDomain } from "./utils-ClP3Chfl.mjs";
import path from "node:path";
//#region lib/routes/18comic/search.ts
init_esm_shims();
const route = {
path: "/search/:option?/:category?/:keyword?/:time?/:order?",
categories: ["anime"],
example: "/18comic/search/photos/all/NTR",
parameters: {
option: "选项,可选 `video` 和 `photos`,默认为 `photos`",
category: "分类,同上表,默认为 `all` 即全部",
keyword: "关键字,同上表,默认为空",
time: "时间范围,同上表,默认为 `a` 即全部",
order: "排列顺序,同上表,默认为 `mr` 即最新"
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
nsfw: true
},
radar: [{
source: ["jmcomic.group/"],
target: "/:category?/:time?/:order?/:keyword?"
}],
name: "搜索",
maintainers: [],
handler,
url: "jmcomic.group/",
description: `::: tip
关键字必须超过两个字,这是来自网站的限制。
:::`
};
async function handler(ctx) {
const option = ctx.req.param("option") ?? "photos";
const category = ctx.req.param("category") ?? "all";
const keyword = ctx.req.param("keyword") ?? "";
const time = ctx.req.param("time") ?? "a";
const { domain = defaultDomain } = ctx.req.query();
const rootUrl = getRootUrl(domain);
let order = ctx.req.param("order") ?? "mr";
const currentUrl = `${rootUrl}/search/${option}${category === "all" ? "" : `/${category}`}${keyword ? `?search_query=${keyword}` : "?"}${time === "a" ? "" : `&t=${time}`}${order === "mr" ? "" : `&o=${order}`}`;
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 20;
let apiUrl = getApiUrl();
order = time === "a" ? order : `${order}_${time}`;
apiUrl = `${apiUrl}/search?search_query=${keyword}&o=${order}`;
const apiResult = await processApiItems(apiUrl);
let filteredItemsByCategory = apiResult.content;
if (category !== "all") filteredItemsByCategory = apiResult.content.filter((item) => item.category.title === apiMapCategory(category));
filteredItemsByCategory = filteredItemsByCategory.slice(0, limit);
const results = await Promise.all(filteredItemsByCategory.map((item) => cache_default.tryGet(`18comic:search:${item.id}`, async () => {
const result = {
title: item.name,
link: `${rootUrl}/album/${item.id}`,
guid: `18comic:/album/${item.id}`,
updated: parseDate(item.update_at)
};
const apiResult$1 = await processApiItems(`${getApiUrl()}/album?id=${item.id}`);
result.pubDate = /* @__PURE__ */ new Date(apiResult$1.addtime * 1e3);
result.category = apiResult$1.tags.map((tag) => tag);
result.author = apiResult$1.author.map((a) => a).join(", ");
result.description = art(path.join(__dirname, "templates/description-afe7e434.art"), {
introduction: apiResult$1.description,
images: [`https://cdn-msp3.${domain}/media/albums/${item.id}_3x4.jpg`],
cover: `https://cdn-msp3.${domain}/media/albums/${item.id}_3x4.jpg`,
category: result.category
});
return result;
})));
return {
title: `Search Results For '${keyword}' - 禁漫天堂`,
link: currentUrl.replace(/\?$/, ""),
item: results,
allowEmpty: true
};
}
//#endregion
export { route };