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

Commit 1c0cb9c

Browse files
committed
2.0-beta.3
1 parent 029d73c commit 1c0cb9c

5 files changed

Lines changed: 27 additions & 29 deletions

File tree

cache.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@ class Cache {
1313
this.uptime();
1414
}
1515

16-
get(key: string): undefined | any {
16+
get(key: string): undefined | any { //@ts-ignore
1717
const value = this.caches[key];
18-
if (this.exist(key)) {
18+
if (this.exist(key)) { //@ts-ignore
1919
return JSON.parse(value.value);
2020
}
2121
}
2222

23-
set(key: string, value: any): void {
23+
set(key: string, value: any): void { //@ts-ignore
2424
this.caches[key] = {
2525
value: JSON.stringify(value),
2626
expiration: (new Date().getTime() / 1000) + this.expiration,
2727
}
2828
}
2929

30-
exist(key: string): boolean {
30+
exist(key: string): boolean { //@ts-ignore
3131
const value = this.caches[key];
3232
return (!!value) && (value.expiration > (new Date().getTime() / 1000));
3333
}
3434

35-
remove(key: string): boolean {
35+
remove(key: string): boolean { //@ts-ignore
3636
return delete this.caches[key];
3737
}
3838

3939
uptime(): void {
4040
const _this = this;
4141
setInterval(function (){
4242
let n: number = 0;
43-
for (const key in _this.caches) {
43+
for (const key in _this.caches) { //@ts-ignore
4444
if (_this.caches[key].expiration < (new Date().getTime() / 1000)) {
4545
_this.remove(key); n++;
4646
}

config.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
export default {
2-
token: process.env.CODE_STATISTIC, // GitHub Access Token (Minimum permissions). Increase QPS of GitHub APIs.
3-
expiration: 3600, // expiration second
4-
requires: ["*"], // CODE STATISTIC can only be parsed for allowed users. ( * indicates that all users are allowed )
5-
port: 8000, // server port
6-
}
1+
2+
export const token: string | undefined = process.env.CODE_STATISTIC; // GitHub Access Token (Minimum permissions). Increase QPS of GitHub APIs.
3+
export const expiration: number = 3600; // expiration second
4+
export const requires: string[] = ["*"]; // CODE STATISTIC can only be parsed for allowed users. ( * indicates that all users are allowed )
5+
export const port: number = 8000; // server port

index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ app.get('/repo/:user/:repo/', async function (req: any, res: any) {
3838
}
3939
});
4040

41-
4241
app.listen(conf.port, () =>
4342
logger.info(`Starting deployment server at http://127.0.0.1:${conf.port}/.`));

stats.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,49 @@ const colors = {"1C Enterprise":"#814CCC","2-Dimensional Array":"#38761D","4D":"
77
async function analysis(queue: Promise<object>[]) {
88
const res: object = {};
99
for (const idx in queue) {
10-
const resp: object = await queue[idx];
10+
const resp: object = await queue[idx]; //@ts-ignore
1111
for (const lang in resp) lang in res ? res[lang] += resp[lang] : res[lang] = resp[lang];
1212
}
1313
return formatter(res);
1414
}
1515

1616
function formatter(langs: object): object[] {
1717
const arr: number[] = utils.sort(Object.values(langs)).reverse();
18-
const total: number = utils.sum(arr);
18+
const total: number = utils.sum(arr); //@ts-ignore
1919
for (let k in langs) { langs[langs[k]] = k; delete langs[k] }
2020
let cursor: number = 0;
21-
return arr.map((key: number): object => {
21+
return arr.map((key: number): object => { //@ts-ignore
2222
const lang: string = langs[key];
2323
const ratio: number = key / total; cursor += ratio;
24-
return {
24+
return { //@ts-ignore
2525
name: lang, color: colors[lang],
2626
cursor: cursor - ratio, ratio: ratio,
2727
text: `${lang} ${(ratio * 100).toFixed(0)}% (${utils.decConvert(key, false)})`,
2828
}});
2929
}
3030

31-
export async function getAccount(username, dark=false) {
32-
const response = await cache.requestWithCache(`/users/${username}`);
31+
export async function getAccount(username: string, dark: boolean = false) {
32+
const response = await utils.requestUser(username);
3333
const repos = await utils.listRepos(username);
3434
return {
3535
dark: dark,
3636
org: response['type'] !== 'User',
37-
location: response['location'],
38-
stars: utils.decConvert(utils.sum(repos.map(repo => repo['stargazers_count']))),
39-
forks: utils.decConvert(utils.sum(repos.map(repo => repo['forks_count']))),
40-
issues: utils.decConvert(utils.sum(repos.map(repo => repo['open_issues_count']))),
41-
watchers: utils.decConvert(utils.sum(repos.map(repo => repo['watchers_count']))),
37+
location: response['location'], //@ts-ignore
38+
stars: utils.decConvert(utils.sum(repos.map(repo => repo['stargazers_count']))), //@ts-ignore
39+
forks: utils.decConvert(utils.sum(repos.map(repo => repo['forks_count']))), //@ts-ignore
40+
issues: utils.decConvert(utils.sum(repos.map(repo => repo['open_issues_count']))), //@ts-ignore
41+
watchers: utils.decConvert(utils.sum(repos.map(repo => repo['watchers_count']))), //@ts-ignore
4242
username: username,
4343
followers: utils.decConvert(response['followers']),
4444
repos: response['public_repos'],
45-
langs: await analysis(
45+
langs: await analysis( //@ts-ignore
4646
repos.map(async (resp) => {
4747
return await utils.requestLanguage(username, resp['name']);
4848
})),
4949
};
5050
}
5151

52-
export async function getRepository(username, repo, dark=false) {
52+
export async function getRepository(username: string, repo: string, dark: boolean = false) {
5353
const res = await utils.requestRepo(username, repo);
5454
return {
5555
dark : dark,
@@ -59,7 +59,7 @@ export async function getRepository(username, repo, dark=false) {
5959
forks: utils.decConvert(res['forks']),
6060
stars: utils.decConvert(res['stargazers_count']),
6161
watchers: utils.decConvert(res['watchers_count']),
62-
license: utils.getLicense(res['license']),
62+
license: utils.getLicense(res['license']), //@ts-ignore
6363
color: colors[res['language']],
6464
langs: formatter(await utils.requestLanguage(username, repo)),
6565
};

utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ export async function requestUser(user: string): Promise<any> {
5252
return await request(`/users/${user}`);
5353
}
5454

55-
export async function listRepos(user: string): Promise<object> {
56-
return Object.values(await request(`/users/${user}/repos`)).filter((repo: object): boolean => !repo['fork']);
55+
export async function listRepos(user: string): Promise<any> {
56+
return Object.values(await request(`/users/${user}/repos`)).filter((repo: any): boolean => !repo['fork']);
5757
}
5858

5959
export async function requestRepo(user: string, repo: string): Promise<any> {

0 commit comments

Comments
 (0)