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

Commit 6e14406

Browse files
committed
2.5.1
es6 style
1 parent ca0b13c commit 6e14406

4 files changed

Lines changed: 38 additions & 38 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div align="center">
22

3-
[![Code Statistic](/public/favicon.png)](https://stats.deeptrain.net)
3+
[<img src="public/favicon.png" alt="Code Statistic" width="64" height="64" style="transform: translateY(50px);">](https://stats.deeptrain.net)
44
# [Code Statistic](https://stats.deeptrain.net)
55

66
#### Dynamically analysis the code for each language in the repository/user and generate the results for your GitHub account and repo README.

index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const server = require("./server");
1+
import { createServer } from "./server";
22

3-
server.createServer();
3+
createServer();

server.ts

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,14 @@
1-
const logger = (require("log4js")).getLogger("Backend");
2-
const stats = require('./stats');
3-
const conf = require('./config');
4-
const utils = require('./utils');
5-
const express = require('express');
6-
7-
logger.level = "debug";
1+
import { getLogger } from "log4js";
2+
import { isAuthenticated, isExistRepo } from "./utils";
3+
import { analyseRepo, analyseUser } from "./stats";
4+
import { port } from "./config";
85

96

10-
function renderError(res: any, dark: boolean = false): void {
11-
return res.render('error', {dark: dark});
12-
}
7+
const express = require('express');
8+
const logger = getLogger("Backend");
9+
logger.level = "debug";
1310

14-
async function renderUser(res: any, username: string, dark: boolean = false): Promise<void> {
15-
if (! await utils.isAuthenticated(username)) {
16-
renderError(res, dark);
17-
} else {
18-
const resp = await stats.analyseUser(username);
19-
resp['dark'] = dark;
20-
res.render('user', resp);
21-
}
22-
}
2311

24-
async function renderRepo(res: any, username: string, repo: string, dark: boolean = false): Promise<void> {
25-
if (! await utils.isExistRepo(username, repo)) {
26-
renderError(res, dark);
27-
} else {
28-
const resp = await stats.analyseRepo(username, repo);
29-
resp['dark'] = dark;
30-
res.render('repo', resp);
31-
}
32-
}
3312
export function createServer(): void {
3413
const app = express();
3514

@@ -45,7 +24,17 @@ export function createServer(): void {
4524
const dark: boolean = req.query['theme'] === 'dark',
4625
username: string = req.params['user'];
4726

48-
try { await renderUser(res, username, dark) } catch { renderError(res, dark) }
27+
try {
28+
if (! await isAuthenticated(username)) {
29+
res.render('error', { dark: dark });
30+
} else {
31+
const resp = await analyseUser(username);
32+
resp['dark'] = dark;
33+
res.render('user', resp);
34+
}
35+
} catch {
36+
res.render('error', {dark: dark});
37+
}
4938
});
5039

5140
app.get('/repo/:user/:repo/', async function (req: any, res: any) {
@@ -55,9 +44,19 @@ export function createServer(): void {
5544
username = req.params['user'],
5645
repo = req.params['repo'];
5746

58-
try { await renderRepo(res, username, repo, dark) } catch { renderError(res, dark) }
47+
try {
48+
if (! await isExistRepo(username, repo)) {
49+
res.render('error', {dark: dark});
50+
} else {
51+
const resp = await analyseRepo(username, repo);
52+
resp['dark'] = dark;
53+
res.render('repo', resp);
54+
}
55+
} catch {
56+
res.render('error', {dark: dark});
57+
}
5958
});
6059

61-
app.listen(conf.port, () =>
62-
logger.info(`Starting deployment server at http://127.0.0.1:${conf.port}/.`));
60+
app.listen(port, () =>
61+
logger.info(`Starting deployment server at http://127.0.0.1:${port}/.`));
6362
}

utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const axios = require("axios");
2-
const conf = require("./config");
3-
const cache = require("./cache").cache;
1+
import axios from "axios";
2+
import * as conf from "./config";
3+
import { cache } from "./cache";
4+
45

56
axios.defaults.baseURL = "https://api.github.com";
67

0 commit comments

Comments
 (0)