UNPKG

rsshub

Version:
77 lines (75 loc) 2.61 kB
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 { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { n as fetchUserDate, t as baseUrl } from "./utils-CEzs3KSX.mjs"; import path from "node:path"; import dayjs from "dayjs"; //#region lib/routes/zhiy/post.ts init_esm_shims(); const route = { path: "/posts/:author", categories: ["new-media"], example: "/zhiy/posts/long", parameters: { author: "作者 ID,可在URL中找到" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["zhiy.cc/:author"] }], name: "笔记", maintainers: ["TonyRL"], handler }; async function handler(ctx) { art.defaults.imports = { dayjs, ...art.defaults.imports }; const author = ctx.req.param("author"); const { author_id: authorId, author_name: authorName, author_signature: authorSignature, author_avatar_url: authorAvatarUrl } = await fetchUserDate(author); const { data: { result: posts } } = await got_default(`${baseUrl}/api/app/share/garden/users/${authorId}/posts`, { searchParams: { page: 1, limit: ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 100 } }); const list = posts.map((item) => ({ title: item.title, pubDate: parseDate(item.create_time, "X"), link: `${baseUrl}/b${item.share_md5}`, guid: `${baseUrl}/b${item.share_md5}:${item.link_amount}:${item.note_amount}`, postId: item.id, shareMD5: item.share_md5 })); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const { data: postMeta } = await got_default(`${baseUrl}/api/app/share/posts/${item.shareMD5}`); const { data: { result: posts$1 } } = await got_default(`${baseUrl}/api/app/share/posts/${item.postId}/notes`, { searchParams: { page: 1, limit: 100 } }); item.description = art(path.join(__dirname, "templates/post-2ebad52a.art"), { postMeta, postDate: dayjs(postMeta.create_time, "X").format("YYYY-MM-DD HH:mm:ss"), posts: posts$1 }); return item; }))); return { title: authorName, link: `${baseUrl}/${author}`, description: authorSignature, image: authorAvatarUrl, item: items }; } //#endregion export { route };