mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-03-13 10:30:18 +08:00
feat(route): add news.qq.com user homepage route (#21280)
* add user.ts * remove async * use relative path * update * fix timestamp * use parseDate * try to fix import-sort?
This commit is contained in:
@@ -16,7 +16,7 @@ export const route: Route = {
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
name: '用户作品评论动态',
|
||||
name: '全民K歌 - 用户作品评论动态',
|
||||
maintainers: ['zhangxiang012'],
|
||||
handler,
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ export const route: Route = {
|
||||
supportPodcast: true,
|
||||
supportScihub: false,
|
||||
},
|
||||
name: '用户作品列表',
|
||||
name: '全民K歌 - 用户作品列表',
|
||||
maintainers: ['zhangxiang012'],
|
||||
handler,
|
||||
};
|
||||
|
||||
86
lib/routes/qq/news/user.ts
Normal file
86
lib/routes/qq/news/user.ts
Normal file
@@ -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: `<p>${item.abstract}</p><img src="${item.miniProShareImage}" />`,
|
||||
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()!
|
||||
: `<p>${item.abstract}</p><img src="${item.miniProShareImage}" /><h4>文章包含非文本内容,请在浏览器中打开查看</h4>`;
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user