mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-03 02:28:23 +08:00
52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
const got = require('@/utils/got');
|
||
const config = require('@/config').value;
|
||
|
||
module.exports = async (ctx) => {
|
||
if (!config.github || !config.github.access_token) {
|
||
throw '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.params.user;
|
||
const repo = ctx.params.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();
|
||
|
||
ctx.state.data = {
|
||
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}`,
|
||
})),
|
||
};
|
||
};
|