Skip to content

Commit

Permalink
Last touches
Browse files Browse the repository at this point in the history
  • Loading branch information
ericciarla committed May 27, 2024
1 parent bbab77f commit 38d70cc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
5 changes: 4 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
env: {
GITHUB_TOKEN: process.env.GITHUB_TOKEN,
G1: process.env.G1,
G2: process.env.G2,
G3: process.env.G3,
G4: process.env.G4,
},
};

Expand Down
Binary file modified src/app/favicon.ico
Binary file not shown.
6 changes: 2 additions & 4 deletions src/components/data-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,12 @@ export default function DataInput({
<Button variant="outline">Cancel</Button>
<Button
onClick={async () => {
const token = process.env.GITHUB_TOKEN;

if (token && repoUrl) {
if (repoUrl) {
try {
const response = await fetch(
`/api/githubStars?repo=${encodeURIComponent(
repoUrl
)}&token=${encodeURIComponent(token)}`
)}`
);
if (!response.ok) {
throw new Error(`Error: ${response.statusText}`);
Expand Down
15 changes: 10 additions & 5 deletions src/pages/api/githubStars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ async function getRepoStarRecords(repo: string, token: string, maxRequestAmount:
const sortedDates = Array.from(starRecordsMap.keys()).sort((a, b) => new Date(a).getTime() - new Date(b).getTime());
const dates = sortedDates.map(date => new Date(date).getTime());
const stars = sortedDates.map(date => starRecordsMap.get(date)!);
console.log(sortedDates);
console.log(stars);
//console.log(sortedDates);
//console.log(stars);

const nonInterpolatedRecords: { Date: string, Stars: number | null }[] = [];
const startDate1 = new Date(sortedDates[0]);
Expand Down Expand Up @@ -153,7 +153,7 @@ async function getRepoStarRecords(repo: string, token: string, maxRequestAmount:
}

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { repo: rawRepo, token } = req.query as { repo: string, token: string };
const { repo: rawRepo } = req.query as { repo: string };

let repo = rawRepo;
if (repo.startsWith('https://github.com/')) {
Expand All @@ -167,10 +167,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}

const maxRequestAmount = 20;
//random number between 1 and 4
const randomNumber = Math.floor(Math.random() * 4) + 1;
const token = process.env[`G${randomNumber}`];
//console.log(`Select G${randomNumber}`);
//console.log(token);

try {
const starRecords = await getRepoStarRecords(repo, token, maxRequestAmount);
console.log(starRecords);
const starRecords = await getRepoStarRecords(repo, token!, maxRequestAmount);
//console.log(starRecords);
res.status(200).json(starRecords);
} catch (error: any) {
res.status(500).json({ error: error.message });
Expand Down

0 comments on commit 38d70cc

Please sign in to comment.