Files
RSSHub/lib/routes/github/starred-repos.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

88 lines
2.7 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: '/starred_repos/:user',
categories: ['programming'],
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>');
}
const user = ctx.req.param('user');
const host = `https://github.com/${user}?tab=stars`;
const url = 'https://api.github.com/graphql';
const response = await got({
method: 'post',
url,
headers: {
Authorization: `bearer ${config.github.access_token}`,
},
json: {
query: `
{
user(login: "${user}") {
starredRepositories(first: 10, orderBy: {direction: DESC, field: STARRED_AT}) {
edges {
starredAt
node {
name
description
url
openGraphImageUrl
primaryLanguage {
name
}
stargazers {
totalCount
}
}
}
}
}
}
`,
},
});
const data = response.data.data.user.starredRepositories.edges;
return {
allowEmpty: true,
title: `${user}’s starred repositories`,
link: host,
description: `${user}’s starred repositories`,
item: data.map((repo) => ({
title: `${user} starred ${repo.node.name}`,
author: user,
description: `${repo.node.description === null ? 'no description' : repo.node.description} <br> primary language: ${
repo.node.primaryLanguage === null ? 'no primary language' : repo.node.primaryLanguage.name
} <br> stargazers: ${repo.node.stargazers.totalCount} <br> <img sytle="width:50px;" src='${repo.node.openGraphImageUrl}'>`,
pubDate: new Date(repo.starredAt),
link: repo.node.url,
})),
};
}