From b49df679df71cd4c08924c3717b66052cf6924d3 Mon Sep 17 00:00:00 2001 From: Stephen Zhou Date: Thu, 11 Jul 2024 02:25:22 +0800 Subject: [PATCH] feat(route): github user activity (#16140) * feat: new route github user activity * Apply suggestions from code review --------- --- lib/routes/github/activity.ts | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lib/routes/github/activity.ts diff --git a/lib/routes/github/activity.ts b/lib/routes/github/activity.ts new file mode 100644 index 000000000..0e1ffa7a1 --- /dev/null +++ b/lib/routes/github/activity.ts @@ -0,0 +1,54 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; +import Parser from 'rss-parser'; + +const parser = new Parser(); + +export const route: Route = { + path: '/activity/:user', + name: 'User Activities', + maintainers: ['hyoban'], + example: '/github/activity/DIYgod', + categories: ['programming'], + parameters: { + user: 'GitHub username', + }, + description: 'Get the activities of a user on GitHub, based on the GitHub official RSS feed', + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['github.com/:user'], + target: '/activity/:user', + }, + ], + handler: async (ctx) => { + const { user } = ctx.req.param(); + const response = (await ofetch(`https://github.com/${user}.atom`)) as Blob; + const raw = await response.text(); + // + const image = raw.match(/ ({ + title: item.title ?? '', + link: item.link, + description: item.content?.replace(/href="(.+?)"/g, `href="https://github.com$1"`), + pubDate: item.pubDate ? parseDate(item.pubDate) : undefined, + author: item.author, + id: item.id, + image, + })), + }; + }, +};