rsshub
Version:
Make RSS Great Again!
50 lines (49 loc) • 1.71 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { t as parseContent } from "./utils--zTDY5Nh.mjs";
import { load } from "cheerio";
//#region lib/routes/piapro/public.ts
const base = "https://piapro.jp";
const types = /* @__PURE__ */ new Set([
"music",
"illust",
"text"
]);
const route = {
path: "/public/:type/:tag?/:category?",
categories: ["social-media"],
example: "/piapro/public/music/miku/2",
parameters: {
type: "work type, can be `music`,`illust`,`text`",
tag: "`tag` parameter in url",
category: "category ID, `categoryId` parameter in url"
},
name: "Website latest works",
maintainers: ["hoilc"],
handler
};
async function handler(ctx) {
const params = ctx.req.param();
const type = types.has(params.type) ? params.type : "music";
const tag = params.tag ?? "";
const category = params.category ?? "";
const url = `${base}/${type}/?tag=${encodeURIComponent(tag)}&categoryId=${category}`;
const $ = load(await rofetch(url));
const typeName = $("head title").text().split("|").pop();
const tagName = $(".tmblist_sort_box").eq(0).find(".option_selected a").text();
const categoryName = $(".tmblist_sort_box").eq(1).find(".option_selected a").text();
const list = $(".tmblist_list li > a:first-child").toArray().map((item) => base + $(item).attr("href"));
const items = await Promise.all(list.slice(0, 10).map((link) => cache_default.tryGet(link, async () => {
return {
...parseContent(await rofetch(link)),
link
};
})));
return {
title: `piapro - ${typeName}${tag ? " - " + tagName : ""}${category ? " - " + categoryName : ""}`,
link: url,
item: items
};
}
//#endregion
export { route };