Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit 7166357

Browse files
committed
0.2
1 parent 98150f4 commit 7166357

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

index.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
const express = require('express');
22
const axios = require('axios');
3+
const token = process.env.CODE_STATISTIC || "";
34
const app = express();
45

56
async function syncAxios(url) {
6-
return (await axios.get(url)).data;
7+
return (await axios.get(url, {
8+
headers: {
9+
Accept: "application/json",
10+
Authorization: `Bearer ${token}`,
11+
}
12+
})).data;
713
}
814

915
async function getLanguage(user, repo) {
1016
return await syncAxios(`https://api.github.com/repos/${user}/${repo}/languages`);
1117
}
18+
19+
async function langStatistics(queue) {
20+
const res = {};
21+
for (const idx in queue) {
22+
const task = queue[idx];
23+
if (task instanceof Promise) {
24+
const task_response = await task;
25+
for (const lang in task_response) {
26+
lang in res ?
27+
res[lang] += task_response[lang] :
28+
res[lang] = task_response[lang];
29+
}
30+
}
31+
}
32+
return res;
33+
}
34+
1235
app.get('/user/:user/', async function (req, res) {
1336
const username = req.params.user;
1437
const response = await syncAxios(`https://api.github.com/users/${username}/repos`);
15-
const statistic = Object.values(response).map(async (resp) => {
38+
const result = await langStatistics(Object.values(response).map(async (resp) => {
1639
return await getLanguage(username, resp['name']);
17-
});
18-
res.send(statistic);
40+
}));
41+
res.send(result);
1942
})
2043

2144
app.get('/repo/:user/:repo/', function (req, res) {

0 commit comments

Comments
 (0)