-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from solana-developers/adding-github-endpoint
adding github validation API
- Loading branch information
Showing
5 changed files
with
91 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ jobs: | |
- name: Replace app.yml secrets | ||
uses: 73h/[email protected] | ||
env: | ||
POSTGRES_STRING: ${{ secrets.POSTGRES_STRING }} # Format: postgres://user:password@/cloudsql/INSTANCE_CONNECTION_NAME/db_name | ||
GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
PROJECT_ID: ${{ secrets.PROJECT_ID }} | ||
DB_USER: ${{ secrets.DB_USER}} | ||
DB_NAME: ${{ secrets.DB_NAME}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import express from "express"; | ||
|
||
const ACCOUNT_AGE_MINIMUM_DAYS = 30; | ||
const router = express.Router(); | ||
|
||
const daysSince = (date) => { | ||
const msPerDay = 1000 * 60 * 60 * 24; | ||
return Math.floor((new Date() - new Date(date)) / msPerDay); | ||
}; | ||
|
||
router.get('/gh-validation/:userId', async (req, res) => { | ||
const { userId } = req.params; | ||
|
||
const GH_TOKEN = process.env.GH_TOKEN; | ||
if (!GH_TOKEN) { | ||
return res.status(500).json({ error: "GitHub token not configured." }); | ||
} | ||
|
||
try { | ||
const response = await fetch(`https://api.github.com/user/${userId}`, { | ||
headers: { | ||
Authorization: `token ${GH_TOKEN}`, | ||
Accept: 'application/vnd.github.v3+json' | ||
} | ||
}); | ||
|
||
if (!response.ok) { | ||
const error = await response.json(); | ||
return res.status(response.status).json({ error: error.message || "GitHub API error." }); | ||
} | ||
const userData = await response.json(); | ||
let valid; | ||
|
||
const accountAge = daysSince(userData.created_at); | ||
valid = accountAge >= ACCOUNT_AGE_MINIMUM_DAYS; | ||
|
||
if(!valid){ | ||
console.error(`Github User ID ${userId} is invalid. Username: ${userData.login}`) | ||
} | ||
res.status(200).json({ | ||
valid, | ||
}); | ||
} catch (error) { | ||
console.error("Error calling GitHub API:", error); | ||
res.status(500).json({ error: "Internal server error." }); | ||
} | ||
}); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import express from 'express'; | ||
import rateLimitRoute from './rateLimitRoute.js'; | ||
import solanaBalancesRoute from "./solanaBalancesRoute.js"; // Import the rate limit routes | ||
import solanaBalancesRoute from "./solanaBalancesRoute.js"; | ||
import githubValidationRoute from "./githubValidationRoute.js"; | ||
|
||
const router = express.Router(); | ||
|
||
// Use rate limit routes | ||
router.use(rateLimitRoute); | ||
|
||
// Use solana balances routes | ||
// Use Solana balances routes | ||
router.use(solanaBalancesRoute); | ||
|
||
// Use Github validation routes | ||
router.use(githubValidationRoute); | ||
|
||
export default router; |