rsshub
Version:
Make RSS Great Again!
56 lines (55 loc) • 1.67 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { t as InvalidParameterError } from "./invalid-parameter-CGxhjomn.mjs";
import { load } from "cheerio";
//#region lib/routes/meihua/shots.ts
const config = {
recommend: {
link: "shots!1!0!0!0!0",
title: "推荐"
},
latest: {
link: "shots!2!0!0!0!0",
title: "最新"
},
hot: {
link: "shots!3!0!0!0!0",
title: "热门"
}
};
const route = {
path: "/shots/:caty",
categories: ["new-media"],
example: "/meihua/shots/latest",
parameters: { caty: "分类,见下表" },
name: "作品",
maintainers: ["nczitzk"],
description: `| 最新 | 热门 | 推荐 |
| ------ | ---- | --------- |
| latest | hot | recommend |`,
handler
};
async function handler(ctx) {
const { caty } = ctx.req.param();
const cfg = config[caty];
if (!cfg) throw new InvalidParameterError(`Bad category: ${caty}`);
const currentUrl = `https://www.meihua.info/${cfg.link}`;
const response = await rofetch(currentUrl);
const shotList = JSON.parse(response.match(/"shotsStore":(.*?),"commentStore":/)[1]).shotsData.list.map((item) => ({
title: item.title,
link: `https://www.meihua.info/shots/${item.compositionId}`,
pubDate: parseDate(item.gmtPublish)
}));
const items = await Promise.all(shotList.map((item) => cache_default.tryGet(item.link, async () => {
item.description = load(await rofetch(item.link))("div.summary").html();
return item;
})));
return {
title: `${cfg.title}作品 - 梅花网`,
link: currentUrl,
item: items
};
}
//#endregion
export { route };