feat: add routes

This commit is contained in:
DIYgod
2024-03-09 03:06:53 +08:00
parent f8b141ee6e
commit 45f9ea21fb
2092 changed files with 47948 additions and 8143 deletions
+26 -4
View File
@@ -1,7 +1,29 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
export default async (ctx) => {
export const route: Route = {
path: '/branches/:user/:repo',
categories: ['design'],
example: '/github/branches/DIYgod/RSSHub',
parameters: { user: 'User name', repo: 'Repo name' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/:user/:repo/branches', 'github.com/:user/:repo'],
},
name: 'Repo Branches',
maintainers: ['max-arnold'],
handler,
};
async function handler(ctx) {
const user = ctx.req.param('user');
const repo = ctx.req.param('repo');
@@ -19,7 +41,7 @@ export default async (ctx) => {
});
const data = response.data;
ctx.set('data', {
return {
title: `${user}/${repo} Branches`,
link: `${host}/branches/all`,
item: data.map((item) => ({
@@ -27,5 +49,5 @@ export default async (ctx) => {
description: item.name,
link: `${host}/commits/${item.name}`,
})),
});
};
};
}
+18 -6
View File
@@ -1,3 +1,4 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import MarkdownIt from 'markdown-it';
@@ -19,7 +20,18 @@ const typeDict = {
},
};
export default async (ctx) => {
export const route: Route = {
path: ['/comments/:user/:repo/:type/:number', '/comments/:user/:repo/:number?'],
radar: {
source: ['github.com/:user/:repo/:type'],
target: '/comments/:user/:repo',
},
name: 'Unknown',
maintainers: [],
handler,
};
async function handler(ctx) {
const user = ctx.req.param('user');
const repo = ctx.req.param('repo');
const number = ctx.req.param('number') && isNaN(Number.parseInt(ctx.req.param('number'))) ? 1 : Number.parseInt(ctx.req.param('number'));
@@ -35,7 +47,7 @@ export default async (ctx) => {
};
await (isNaN(number) ? allIssues(ctx, user, repo, limit, headers) : singleIssue(ctx, user, repo, number, limit, headers));
};
}
async function allIssues(ctx, user, repo, limit, headers) {
const response = await got(`${apiUrl}/repos/${user}/${repo}/issues/comments`, {
@@ -73,11 +85,11 @@ async function allIssues(ctx, user, repo, limit, headers) {
used: Number.parseInt(response.headers['x-ratelimit-used']),
};
ctx.set('data', {
return {
title: `${user}/${repo}: Issue & Pull request comments`,
link: `${rootUrl}/${user}/${repo}`,
item: items,
});
};
ctx.set('json', {
title: `${user}/${repo}: Issue & Pull request comments`,
@@ -165,11 +177,11 @@ async function singleIssue(ctx, user, repo, number, limit, headers) {
}
}
ctx.set('data', {
return {
title: `${user}/${repo}: ${typeDict[type].title} #${number} - ${issue.title}`,
link: issue.html_url,
item: items,
});
};
ctx.set('json', {
title: `${user}/${repo}: ${typeDict[type].title} #${number} - ${issue.title}`,
+27 -4
View File
@@ -1,7 +1,30 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
export default async (ctx) => {
export const route: Route = {
path: '/contributors/:user/:repo/:order?/:anon?',
categories: ['design'],
example: '/github/contributors/DIYgod/RSSHub',
parameters: { user: 'User name', repo: 'Repo name', order: 'Sort order by commit numbers, desc and asc (descending by default)', anon: 'Show anonymous users. Defaults to no, use any values for yes.' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/:user/:repo/graphs/contributors', 'github.com/:user/:repo'],
target: '/contributors/:user/:repo',
},
name: 'Repo Contributors',
maintainers: ['zoenglinghou'],
handler,
};
async function handler(ctx) {
const { user, repo, order, anon } = ctx.req.param();
const host = `https://github.com/${user}/${repo}`;
@@ -70,10 +93,10 @@ export default async (ctx) => {
}
);
ctx.set('data', {
return {
title: `${user}/${repo} Contributors`,
link: `${host}/graphs/contributors`,
description: `New contributors for ${user}/${repo}`,
item: items,
});
};
};
}
+16 -4
View File
@@ -1,8 +1,20 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
import queryString from 'query-string';
export default async (ctx) => {
export const route: Route = {
path: '/file/:user/:repo/:branch/:filepath{.+}',
radar: {
source: ['github.com/:user/:repo/blob/:branch/*filepath'],
target: '/file/:user/:repo/:branch/:filepath',
},
name: 'Unknown',
maintainers: [],
handler,
};
async function handler(ctx) {
const user = ctx.req.param('user');
const repo = ctx.req.param('repo');
const branch = ctx.req.param('branch');
@@ -37,9 +49,9 @@ export default async (ctx) => {
};
});
ctx.set('data', {
return {
title: `GitHub File - ${user}/${repo}/${branch}/${filepath}`,
link: fileUrl,
item: resultItems,
});
};
};
}
+26 -4
View File
@@ -1,7 +1,29 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
export default async (ctx) => {
export const route: Route = {
path: '/user/followers/:user',
categories: ['design'],
example: '/github/user/followers/HenryQW',
parameters: { user: 'GitHub username' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/:user'],
},
name: 'User Followers',
maintainers: ['HenryQW'],
handler,
};
async function handler(ctx) {
if (!config.github || !config.github.access_token) {
throw new Error('GitHub follower RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
}
@@ -36,7 +58,7 @@ export default async (ctx) => {
const data = response.data.data.user.followers.edges;
ctx.set('data', {
return {
allowEmpty: true,
title: `${user}'s followers`,
link: host,
@@ -46,5 +68,5 @@ export default async (ctx) => {
description: `<a href="https://github.com/${follower.node.login}">${follower.node.login}</a> <br> <img sytle="width:50px;" src='${follower.node.avatarUrl}'>`,
link: `https://github.com/${follower.node.login}`,
})),
});
};
};
}
+26 -4
View File
@@ -1,8 +1,30 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
import { parseDate } from '@/utils/parse-date';
export default async (ctx) => {
export const route: Route = {
path: '/gist/:gistId',
categories: ['design'],
example: '/github/gist/d2c152bb7179d07015f336b1a0582679',
parameters: { gistId: 'Gist ID' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['gist.github.com/:owner/:gistId/revisions', 'gist.github.com/:owner/:gistId/stargazers', 'gist.github.com/:owner/:gistId/forks', 'gist.github.com/:owner/:gistId'],
},
name: 'Gist Commits',
maintainers: ['TonyRL'],
handler,
};
async function handler(ctx) {
const gistId = ctx.req.param('gistId');
const headers = { Accept: 'application/vnd.github.v3+json' };
@@ -24,12 +46,12 @@ export default async (ctx) => {
pubDate: parseDate(item.committed_at), // e.g. 2022-09-02T11:09:56Z
}));
ctx.set('data', {
return {
allowEmpty: true,
title: `${response.owner.login} / ${Object.values(response.files)[0].filename}`,
description: response.description,
image: response.owner.avatar_url,
link: `${response.html_url}/revisions`,
item: items,
});
};
};
}
+27 -4
View File
@@ -1,3 +1,4 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
import MarkdownIt from 'markdown-it';
@@ -8,7 +9,29 @@ const md = MarkdownIt({
import queryString from 'query-string';
import { parseDate } from '@/utils/parse-date';
export default async (ctx) => {
export const route: Route = {
path: '/issue/:user/:repo/:state?/:labels?',
categories: ['design'],
example: '/github/issue/vuejs/core/all/wontfix',
parameters: { user: 'GitHub username', repo: 'GitHub repo name', state: 'the state of the issues. Can be either `open`, `closed`, or `all`. Default: `open`.', labels: 'a list of comma separated label names' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/:user/:repo/issues', 'github.com/:user/:repo/issues/:id', 'github.com/:user/:repo'],
target: '/issue/:user/:repo',
},
name: 'Repo Issues',
maintainers: ['HenryQW', 'AndreyMZ'],
handler,
};
async function handler(ctx) {
const user = ctx.req.param('user');
const repo = ctx.req.param('repo');
const state = ctx.req.param('state');
@@ -36,7 +59,7 @@ export default async (ctx) => {
});
const data = response.data;
ctx.set('data', {
return {
allowEmpty: true,
title: `${user}/${repo}${state ? ' ' + state.replace(/^\S/, (s) => s.toUpperCase()) : ''} Issues${labels ? ' - ' + labels : ''}`,
link: host,
@@ -49,5 +72,5 @@ export default async (ctx) => {
author: item.user.login,
link: `${host}/${item.number}`,
})),
});
};
};
}
+26 -4
View File
@@ -1,10 +1,32 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
const apiUrl = 'https://api.github.com';
import { config } from '@/config';
export default async (ctx) => {
export const route: Route = {
path: '/notifications',
categories: ['design'],
example: '/github/notifications',
parameters: {},
features: {
requireConfig: true,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/notifications'],
},
name: 'Notifications',
maintainers: ['zhzy0077'],
handler,
};
async function handler(ctx) {
if (!config.github || !config.github.access_token) {
throw new Error('GitHub trending RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
}
@@ -33,11 +55,11 @@ export default async (ctx) => {
};
});
ctx.set('data', {
return {
title: 'Github Notifications',
link: 'https://github.com/notifications',
item: items,
});
};
ctx.set('json', {
title: 'Github Notifications',
@@ -50,4 +72,4 @@ export default async (ctx) => {
used: Number.parseInt(response.headers['X-RateLimit-Used']),
},
});
};
}
+27 -4
View File
@@ -1,3 +1,4 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
import MarkdownIt from 'markdown-it';
@@ -7,7 +8,29 @@ const md = MarkdownIt({
});
import { parseDate } from '@/utils/parse-date';
export default async (ctx) => {
export const route: Route = {
path: '/pull/:user/:repo/:state?/:labels?',
categories: ['design'],
example: '/github/pull/DIYgod/RSSHub',
parameters: { user: 'User name', repo: 'Repo name', state: 'the state of pull requests. Can be either `open`, `closed`, or `all`. Default: `open`.', labels: 'a list of comma separated label names' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/:user/:repo/pulls', 'github.com/:user/:repo/pulls/:id', 'github.com/:user/:repo'],
target: '/pull/:user/:repo',
},
name: 'Repo Pull Requests',
maintainers: [],
handler,
};
async function handler(ctx) {
const user = ctx.req.param('user');
const repo = ctx.req.param('repo');
const state = ctx.req.param('state') ?? 'open';
@@ -32,7 +55,7 @@ export default async (ctx) => {
});
const data = response.data.filter((item) => item.pull_request);
ctx.set('data', {
return {
allowEmpty: true,
title: `${user}/${repo} Pull requests`,
link: host,
@@ -43,5 +66,5 @@ export default async (ctx) => {
pubDate: parseDate(item.created_at),
link: item.html_url,
})),
});
};
};
}
+30 -4
View File
@@ -1,3 +1,4 @@
import { Route } from '@/types';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);
@@ -8,7 +9,32 @@ import md5 from '@/utils/md5';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
export default async (ctx) => {
export const route: Route = {
path: '/pulse/:user/:repo/:period?',
categories: ['design'],
example: '/github/pulse/DIYgod/RSSHub',
parameters: {
user: 'User name',
repo: 'Repo name',
period: "Time frame, selected from a repository's Pulse/Insights page. Possible values are: `daily`, `halfweekly`, `weekly`, or `monthly`. Default: `weekly`. If your RSS client supports it, consider aligning the polling frequency of the feed to the period.",
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/:user/:repo/pulse', 'github.com/:user/:repo/pulse/:period'],
},
name: 'Repo Pulse',
maintainers: ['jameschensmith'],
handler,
};
async function handler(ctx) {
const { user, repo, period } = ctx.req.param();
const periods = ['daily', 'halfweekly', 'weekly', 'monthly'];
@@ -71,7 +97,7 @@ export default async (ctx) => {
.toArray();
}
ctx.set('data', {
return {
title: `${user}/${repo} ${pulsePeriod} Pulse`,
link,
item: [
@@ -86,5 +112,5 @@ export default async (ctx) => {
pubDate: parseDate(periodTo),
},
],
});
};
};
}
+26 -4
View File
@@ -1,8 +1,30 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
import queryString from 'query-string';
export default async (ctx) => {
export const route: Route = {
path: '/repos/:user',
categories: ['design'],
example: '/github/repos/DIYgod',
parameters: { user: 'GitHub username' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/:user'],
},
name: 'User Repo',
maintainers: ['DIYgod'],
handler,
};
async function handler(ctx) {
const user = ctx.req.param('user');
const headers = {};
@@ -18,7 +40,7 @@ export default async (ctx) => {
headers,
});
const data = response.data;
ctx.set('data', {
return {
allowEmpty: true,
title: `${user}'s GitHub repositories`,
link: `https://github.com/${user}`,
@@ -30,5 +52,5 @@ export default async (ctx) => {
pubDate: new Date(item.created_at).toUTCString(),
link: item.html_url,
})),
});
};
};
}
+23 -4
View File
@@ -1,10 +1,29 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import * as url from 'node:url';
const host = 'https://github.com';
export default async (ctx) => {
export const route: Route = {
path: '/search/:query/:sort?/:order?',
categories: ['design'],
example: '/github/search/RSSHub/bestmatch/desc',
parameters: { query: 'search keyword', sort: 'Sort options (default to bestmatch)', order: 'Sort order, desc and asc (desc descending by default)' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: 'Search Result',
maintainers: ['LogicJake'],
handler,
};
async function handler(ctx) {
const query = ctx.req.param('query');
let sort = ctx.req.param('sort') || 'bestmatch';
const order = ctx.req.param('order') || 'desc';
@@ -32,10 +51,10 @@ export default async (ctx) => {
})
.get();
ctx.set('data', {
return {
allowEmpty: true,
title: `${query}的搜索结果`,
link,
item: out,
});
};
};
}
+26 -4
View File
@@ -1,7 +1,29 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
export default async (ctx) => {
export const route: Route = {
path: '/stars/:user/:repo',
categories: ['design'],
example: '/github/stars/DIYGod/RSSHub',
parameters: { user: 'GitHub username', repo: 'GitHub repo name' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/:user/:repo/stargazers', 'github.com/:user/:repo'],
},
name: 'Repo Stars',
maintainers: ['HenryQW'],
handler,
};
async function handler(ctx) {
if (!config.github || !config.github.access_token) {
throw new Error('GitHub star RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
}
@@ -37,7 +59,7 @@ export default async (ctx) => {
const data = response.data.data.repository.stargazers.edges.reverse();
ctx.set('data', {
return {
allowEmpty: true,
title: `${user}/${repo}’s stargazers`,
link: host,
@@ -47,5 +69,5 @@ export default async (ctx) => {
description: `<a href="https://github.com/${follower.node.login}">${follower.node.login}</a> <br> <img sytle="width:50px;" src='${follower.node.avatarUrl}'>`,
link: `https://github.com/${follower.node.login}`,
})),
});
};
};
}
+26 -4
View File
@@ -1,7 +1,29 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
export default async (ctx) => {
export const route: Route = {
path: '/starred_repos/:user',
categories: ['design'],
example: '/github/starred_repos/DIYgod',
parameters: { user: 'User name' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/:user'],
},
name: 'User Starred Repositories',
maintainers: ['LanceZhu'],
handler,
};
async function handler(ctx) {
if (!config.github || !config.github.access_token) {
throw new Error('GitHub star RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
}
@@ -45,7 +67,7 @@ export default async (ctx) => {
const data = response.data.data.user.starredRepositories.edges;
ctx.set('data', {
return {
allowEmpty: true,
title: `${user}’s starred repositories`,
link: host,
@@ -59,5 +81,5 @@ export default async (ctx) => {
pubDate: new Date(repo.starredAt),
link: repo.node.url,
})),
});
};
};
}
+26 -4
View File
@@ -1,15 +1,37 @@
import { Route } from '@/types';
import { load } from 'cheerio';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
export default async (ctx) => {
export const route: Route = {
path: '/topics/:name/:qs?',
categories: ['design'],
example: '/github/topics/framework',
parameters: { name: 'Topic name, which can be found in the URL of the corresponding [Topics Page](https://github.com/topics/framework)', qs: 'Query string, like `l=php&o=desc&s=stars`. Details listed as follows:' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/topics'],
},
name: 'Topics',
maintainers: ['queensferryme'],
handler,
};
async function handler(ctx) {
const link = `https://github.com/topics/${ctx.req.param('name')}`;
const { data, url } = await got(link, {
searchParams: new URLSearchParams(ctx.req.param('qs')),
});
const $ = load(data);
ctx.set('data', {
return {
title: $('title').text(),
description: $('.markdown-body').text().trim(),
link: url,
@@ -37,5 +59,5 @@ export default async (ctx) => {
pubDate,
};
}),
});
};
};
}
+31 -4
View File
@@ -1,3 +1,4 @@
import { Route } from '@/types';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);
@@ -7,7 +8,33 @@ import { art } from '@/utils/render';
import { load } from 'cheerio';
import * as path from 'node:path';
export default async (ctx) => {
export const route: Route = {
path: '/trending/:since/:language/:spoken_language?',
categories: ['design'],
example: '/github/trending/daily/javascript/en',
parameters: {
since: "time frame, available in [Trending page](https://github.com/trending/javascript?since=monthly) 's URL, possible values are: `daily`, `weekly` or `monthly`",
language: "the feed language, available in [Trending page](https://github.com/trending/javascript?since=monthly) 's URL, don't filter option is `any`",
spoken_language: "natural language, available in [Trending page](https://github.com/trending/javascript?since=monthly) 's URL",
},
features: {
requireConfig: true,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/trending'],
target: '/trending/:since',
},
name: 'Trending',
maintainers: ['DIYgod', 'jameschensmith'],
handler,
};
async function handler(ctx) {
if (!config.github || !config.github.access_token) {
throw new Error('GitHub trending RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
}
@@ -73,7 +100,7 @@ export default async (ctx) => {
return { ...found, ...repo };
});
ctx.set('data', {
return {
title: $('title').text(),
link: trendingUrl,
item: repos.map((r) => ({
@@ -88,5 +115,5 @@ export default async (ctx) => {
}),
link: `https://github.com/${r.nameWithOwner}`,
})),
});
};
};
}
+27 -4
View File
@@ -1,10 +1,33 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
const baseUrl = 'https://github.com';
export default async (ctx) => {
export const route: Route = {
path: '/wiki/:user/:repo/:page?',
categories: ['design'],
example: '/github/wiki/flutter/flutter/Roadmap',
parameters: { user: 'User / Org name', repo: 'Repo name', page: 'Page slug, can be found in URL, empty means Home' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: {
source: ['github.com/:user/:repo/wiki/:page/_history', 'github.com/:user/:repo/wiki/:page', 'github.com/:user/:repo/wiki/_history', 'github.com/:user/:repo/wiki'],
target: '/wiki/:user/:repo/:page',
},
name: 'Wiki History',
maintainers: ['TonyRL'],
handler,
};
async function handler(ctx) {
const { user, repo, page } = ctx.req.param();
const url = `${baseUrl}/${user}/${repo}/wiki${page ? `/${page}` : ''}/_history`;
@@ -24,9 +47,9 @@ export default async (ctx) => {
};
});
ctx.set('data', {
return {
title: `${$('.gh-header-title').text()} - ${user}/${repo}`,
link: url,
item: items,
});
};
};
}