rsshub
Version:
Make RSS Great Again!
58 lines (56 loc) • 2.06 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 "./helpers-DxBp0Pty.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { r as viewThread, t as countReplies } from "./query-BWAtKkTV.mjs";
import path from "node:path";
//#region lib/routes/lkong/thread.ts
init_esm_shims();
const route = {
path: "/thread/:id",
radar: [{ source: ["lkong.com/thread/:id", "lkong.com/"] }],
name: "Unknown",
maintainers: ["nczitzk", "ma6254"],
handler
};
async function handler(ctx) {
const id = ctx.req.param("id");
const rootUrl = "https://www.lkong.com";
const apiUrl = "https://api.lkong.com/api";
const currentUrl = `${rootUrl}/thread/${id}`;
const countResponse = await got_default({
method: "post",
url: apiUrl,
json: countReplies(id)
});
if (countResponse.data.errors) throw new Error(countResponse.data.errors[0].message);
const response = await got_default({
method: "post",
url: apiUrl,
json: viewThread(id, Math.ceil(countResponse.data.data.thread.replies / 20))
});
const items = response.data.data.posts.map((item) => ({
guid: item.pid,
author: item.user.name,
title: `#${item.lou} ${item.user.name}`,
link: `${rootUrl}/thread/${id}?pid=${item.pid}`,
pubDate: parseDate(item.dateline),
description: (item.quote ? art(path.join(__dirname, "templates/quote-0d63bb36.art"), {
target: `${rootUrl}/thread/${id}?pid=${item.quote.pid}`,
author: item.quote.author.name,
content: art(path.join(__dirname, "templates/content-b0aebebb.art"), { content: JSON.parse(item.quote.content) })
}) : "") + art(path.join(__dirname, "templates/content-b0aebebb.art"), { content: JSON.parse(item.content) })
}));
return {
title: `${response.data.data.thread.title} - 龙空`,
link: currentUrl,
item: items
};
}
//#endregion
export { route };