UNPKG

rsshub

Version:
68 lines (66 loc) 2.21 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./ofetch-BIyrKU3Y.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as utils_default } from "./utils-qtmmaZ0W.mjs"; import markdownit from "markdown-it"; //#region lib/routes/lanqiao/author.ts async function getUserName(uid) { return (await got_default({ method: "get", url: `https://www.lanqiao.cn/api/v2/users/${uid}/`, headers: { Referer: `https://www.lanqiao.cn/users/${uid}/` } })).data.name; } const route = { path: "/author/:uid", categories: ["programming"], example: "/lanqiao/author/1701267", parameters: { uid: "作者 `uid` 可在作者主页 URL 中找到" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["lanqiao.cn/users/:uid"] }], name: "作者发布的课程", maintainers: ["huhuhang"], handler }; async function handler(ctx) { const uid = ctx.req.param("uid"); const userName = await getUserName(uid); const data = (await got_default({ method: "get", url: `https://www.lanqiao.cn/api/v2/users/${uid}/courses/?type=published`, headers: { Referer: `https://www.lanqiao.cn/users/${uid}/` } })).data.results; const md = new markdownit(); const items = await Promise.all(data.map((item) => cache_default.tryGet(`https://www.lanqiao.cn/api/v2/courses/${item.id}/`, async () => { const course = (await got_default({ method: "get", url: `https://www.lanqiao.cn/api/v2/courses/${item.id}/` })).data; item.title = course.name; item.description = utils_default.courseDesc(course.picture_url, md.render(course.long_description)); item.author = course.teacher.name; item.link = `https://www.lanqiao.cn/courses/${course.id}/`; return item; }))); return { title: `${userName} 发布的课程`, link: `https://www.lanqiao.cn/users/${uid}`, description: `${userName} 发布的课程`, item: items }; } //#endregion export { route };