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

Commit 70aa0df

Browse files
committed
0.10
1 parent 4255580 commit 70aa0df

5 files changed

Lines changed: 39 additions & 4 deletions

File tree

config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ module.exports = {
33
expiration: 3600, // expiration second
44
requires: ["*"], // CODE STATISTIC can only be parsed for allowed users. ( * indicates that all users are allowed )
55
port: 8000, // server port
6+
host : "localhost",
67
}

index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
const express = require('express');
22
const cache = new (require('./cache').ApiCache)();
3+
const logger = (require("log4js")).getLogger("Backend");
34
const utils = require('./utils');
45
const conf = require('./config');
56
const app = express();
67

8+
logger.level = "debug";
9+
app.set("view engine","ejs");
10+
711

812
const isAvailableUser = (username) => {
913
return ( !! username ) && ( conf.requires.includes("*") || conf.requires.includes(username));
@@ -29,13 +33,18 @@ async function langStatistics(queue) {
2933
return res;
3034
}
3135

32-
app.get('/:user/', async function (req, res) {
36+
app.get('/', function(req, res) {
37+
res.send("<p>User Code Analysis: <strong>/user/:user/</strong> (e.g. /user/zmh-program/)</p>" +
38+
"<p>Repo Code Statistic: <strong>/repo/:user/:repo/</strong> (e.g. /repo/zmh-program/admin-pages/)</p>")
39+
})
40+
app.get('/user/:user/', async function (req, res) {
3341
const username = req.params['user'];
3442
if ( ! isAvailableUser(username) ) {
3543
res.send('permission denied');
3644
return;
3745
}
3846
const response = await cache.requestWithCache(`/users/${username}`);
47+
res.type('svg');
3948
res.send({
4049
followers: response['followers'],
4150
repos: response['public_repos'],
@@ -47,14 +56,14 @@ app.get('/:user/', async function (req, res) {
4756
});
4857
});
4958

50-
app.get('/:user/:repo/', async function (req, res) {
59+
app.get('/repo/:user/:repo/', async function (req, res) {
5160
const username = req.params['user'], repo = req.params['repo'];
5261
if ( ! isAvailableUser(username) ) {
5362
res.send('permission denied');
5463
return;
5564
}
5665
const info = await cache.requestWithCache(`/repos/${username}/${repo}`);
57-
66+
res.type('svg');
5867
res.send({
5968
size: utils.storeConvert(info['size'], 1),
6069
forks: info['forks'],
@@ -67,4 +76,7 @@ app.get('/:user/:repo/', async function (req, res) {
6776
});
6877

6978

70-
app.listen(conf.port);
79+
80+
logger.info(`Starting deployment server at http://${conf.host}:${conf.port}/.`)
81+
82+
app.listen(conf.port, conf.host);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"homepage": "https://github.com/zmh-program/codeline-statistic#readme",
2222
"dependencies": {
2323
"axios": "^1.3.2",
24+
"ejs": "^3.1.8",
2425
"express": "^4.18.2",
2526
"log4js": "^6.7.1"
2627
}

views/repo.ejs

Whitespace-only changes.

views/user.ejs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="132" height="20" role="img" aria-label="404: badge not found">
2+
<title>404: badge not found</title>
3+
<linearGradient id="s" x2="0" y2="100%">
4+
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
5+
<stop offset="1" stop-opacity=".1"/>
6+
</linearGradient>
7+
<clipPath id="r">
8+
<rect width="132" height="20" rx="3" fill="#fff"/>
9+
</clipPath>
10+
<g clip-path="url(#r)">
11+
<rect width="31" height="20" fill="#555"/>
12+
<rect x="31" width="101" height="20" fill="#e05d44"/>
13+
<rect width="132" height="20" fill="url(#s)"/>
14+
</g>
15+
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
16+
<text aria-hidden="true" x="165" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="210">404</text>
17+
<text x="165" y="140" transform="scale(.1)" fill="#fff" textLength="210">404</text>
18+
<text aria-hidden="true" x="805" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="910">badge not found</text>
19+
<text x="805" y="140" transform="scale(.1)" fill="#fff" textLength="910">badge not found</text>
20+
</g>
21+
</svg>

0 commit comments

Comments
 (0)