File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments