Skip to content

Commit 0868081

Browse files
committed
New backers API
1 parent 66a056b commit 0868081

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

pages/api/v2/backers.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { NextApiRequest, NextApiResponse } from "next";
2+
import fetch from "node-fetch";
3+
import { GitHubService } from "../../../services/GithubService";
4+
5+
const api = async (req: NextApiRequest, res: NextApiResponse) => {
6+
const { token } = req.body;
7+
8+
if (!token) {
9+
return res.status(403).send({});
10+
}
11+
12+
const username = await GitHubService.getUser(token);
13+
if (!username) {
14+
return res.status(403).send({});
15+
}
16+
17+
const backers = process.env.BACKERS || "";
18+
const allBackers = backers.split(",");
19+
if (allBackers.includes(username)) {
20+
return res.status(200).send(`Thanks for your support ${username}!`);
21+
}
22+
23+
const sponsors = await GitHubService.getSponsors();
24+
const sponsor = sponsors.find((s: any) => s.login === username);
25+
if (sponsor) {
26+
return res.status(200).send(`Thanks for your support ${username}!`);
27+
}
28+
29+
return res.status(403).send({});
30+
};
31+
32+
export default api;

0 commit comments

Comments
 (0)