diff --git a/lib/routes/qq/kg/reply.ts b/lib/routes/qq/kg/reply.ts index 70dd6ea39c..91fdcedd88 100644 --- a/lib/routes/qq/kg/reply.ts +++ b/lib/routes/qq/kg/reply.ts @@ -16,7 +16,7 @@ export const route: Route = { supportPodcast: false, supportScihub: false, }, - name: '用户作品评论动态', + name: '全民K歌 - 用户作品评论动态', maintainers: ['zhangxiang012'], handler, }; diff --git a/lib/routes/qq/kg/user.ts b/lib/routes/qq/kg/user.ts index e42812c210..44c7ec22a9 100644 --- a/lib/routes/qq/kg/user.ts +++ b/lib/routes/qq/kg/user.ts @@ -19,7 +19,7 @@ export const route: Route = { supportPodcast: true, supportScihub: false, }, - name: '用户作品列表', + name: '全民K歌 - 用户作品列表', maintainers: ['zhangxiang012'], handler, }; diff --git a/lib/routes/qq/news/user.ts b/lib/routes/qq/news/user.ts new file mode 100644 index 0000000000..2dbb2d7bdd --- /dev/null +++ b/lib/routes/qq/news/user.ts @@ -0,0 +1,86 @@ +import { load } from "cheerio"; + +import type { DataItem, Route } from "@/types"; +import cache from "@/utils/cache"; +import ofetch from "@/utils/ofetch"; +import { parseDate } from "@/utils/parse-date"; + +interface NewsItem { + id: string; + uinnick: string; + articletype: string; + longtitle: string; + url: string; + timestamp: number; + abstract: string; + miniProShareImage: string; +} + +export const route: Route = { + path: "/news/:uid/:detail?", + categories: ["social-media"], + example: "/qq/news/8QMZ2X5a5YUeujw=", + parameters: { + uid: "用户 ID, 用户主页 URL 中的最后一段部分", + detail: "是否抓取全文,该值只要不为空就抓取全文返回,否则只返回摘要", + }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: true, + supportScihub: false, + }, + radar: [ + { + source: ["news.qq.com/omn/author/:uid"], + target: "/qq/news/:uid", + }, + ], + name: "用户主页列表", + maintainers: ["hualiong"], + handler, +}; + +async function handler(ctx) { + const { uid, detail } = ctx.req.param(); + const url = `https://i.news.qq.com/getSubNewsMixedList?guestSuid=${uid}&tabId=om_index`; + const response = await ofetch<{ ret: number; newslist: NewsItem[] }>(url); + + let news = response.newslist.map((item) => ({ + title: item.longtitle, + description: `

${item.abstract}

`, + guid: item.id, + link: item.url, + author: item.uinnick, + pubDate: parseDate(item.timestamp * 1000), + }) satisfies DataItem); + + if (detail) { + news = await Promise.all( + response.newslist.map((item) => + cache.tryGet(item.id, async () => { + const description = + item.articletype === "0" + ? load(await ofetch(`https://news.qq.com/rain/a/${item.id}`))(".rich_media_content").html()! + : `

${item.abstract}

文章包含非文本内容,请在浏览器中打开查看

`; + return { + title: item.longtitle, + description, + guid: item.id, + link: item.url, + author: item.uinnick, + pubDate: parseDate(item.timestamp * 1000), + } satisfies DataItem; + }), + ), + ); + } + + return { + title: `${response.newslist[0].uinnick}的主页 - 腾讯网`, + link: `https://news.qq.com/omn/author/${uid}`, + item: news, + }; +}