Files
RSSHub/lib/routes/github/star.ts
T
Tony d585a87daf fix: allow multiple radar rules per route (#14800)
* fix: allow multiple radar rules per route

* fix: github folder

* feat: add namespace to radar target

* docs: fix types url
2024-03-16 03:28:44 +08:00

76 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Route } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
export const route: Route = {
path: '/stars/:user/:repo',
categories: ['programming'],
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>');
}
const user = ctx.req.param('user');
const repo = ctx.req.param('repo');
const host = `https://github.com/${user}/${repo}/stargazers`;
const url = 'https://api.github.com/graphql';
const response = await got({
method: 'post',
url,
headers: {
Authorization: `bearer ${config.github.access_token}`,
},
json: {
query: `
{
repository(owner: "${user}", name: "${repo}") {
stargazers(last: 10) {
edges {
node {
login
avatarUrl
}
}
}
}
}
`,
},
});
const data = response.data.data.repository.stargazers.edges.reverse();
return {
allowEmpty: true,
title: `${user}/${repo}’s stargazers`,
link: host,
item: data.map((follower) => ({
title: `${follower.node.login} starred ${user}/${repo}`,
author: follower.node.login,
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}`,
})),
};
}