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

Commit ee13c56

Browse files
committed
0.6
1 parent 7635922 commit ee13c56

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ module.exports = {
22
token: process.env.CODE_STATISTIC, // GitHub Access Token (Minimum permissions). Increase QPS of GitHub APIs.
33
expiration: 3600, // expiration second
44
requires: ["*"], // CODE STATISTIC can only be parsed for allowed users. ( * indicates that all users are allowed )
5+
port: 8000, // server port
56
}

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const express = require('express');
22
const cache = new (require('./cache').ApiCache)();
3+
const utils = require('./utils');
34
const conf = require('./config');
45
const app = express();
56

@@ -47,7 +48,9 @@ app.get('/:user/:repo/', async function (req, res) {
4748
res.send('permission denied');
4849
return;
4950
}
51+
const repo_info = await cache.requestWithCache(`/repos/${username}/${repo}`);
5052
res.send(await getLanguage(username, repo));
5153
})
5254

53-
app.listen(3000);
55+
56+
app.listen(conf.port);

utils.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const units = ["b", "KiB", "MiB", "GiB", "TiB", "PiB"]
2+
const len_units = units.length - 1;
3+
4+
function storeConvert(size) {
5+
if (size <= 0) {
6+
return "0";
7+
}
8+
9+
let idx = 0;
10+
while (idx < len_units && size > 1024) {
11+
console.log(idx, size)
12+
size /= 1024;
13+
idx ++;
14+
}
15+
return `${size.toFixed(1)} ${units[idx]}`;
16+
}
17+
18+
module.exports = {
19+
storeConvert: storeConvert,
20+
}

0 commit comments

Comments
 (0)