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

Commit e4f494b

Browse files
committed
1.9
1 parent 0acf611 commit e4f494b

3 files changed

Lines changed: 41 additions & 14 deletions

File tree

index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,20 @@ app.get('/', function(req, res) {
1919

2020
app.get('/user/:user/', async function (req, res) {
2121
const username = req.params['user'];
22-
if ( ! isAvailableUser(username) ) {
23-
res.send('permission denied');
24-
return;
25-
}
22+
2623
res.type('svg');
27-
res.render('user', await stats.getAccount(username, req.query));
24+
isAvailableUser(username) ?
25+
res.render('user', await stats.getAccount(username, req.query['theme'] === 'dark')):
26+
res.render('error', {dark: req.query['theme'] === 'dark'});
2827
});
2928

3029
app.get('/repo/:user/:repo/', async function (req, res) {
3130
const username = req.params['user'], repo = req.params['repo'];
32-
if ( (! isAvailableUser(username)) || (! repo)) {
33-
res.send('permission denied');
34-
return;
35-
}
31+
3632
res.type('svg');
37-
res.render('repo', await stats.getRepository(username, repo, req.query));
33+
isAvailableUser(username) && repo.length ?
34+
res.render('repo', await stats.getRepository(username, repo, req.query['theme'] === 'dark'))
35+
: res.render('error', {dark: req.query['theme'] === 'dark'});
3836
});
3937

4038

stats.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,11 @@ function langHandler(langs) {
620620
}
621621
});
622622
}
623-
async function getAccount(username, query={}) {
623+
async function getAccount(username, dark=false) {
624624
const response = await cache.requestWithCache(`/users/${username}`);
625625
const repos = Object.values(await cache.requestWithCache(`/users/${username}/repos`)).filter(repo => !repo.fork);
626626
return {
627-
dark : query['theme'] === 'dark',
627+
dark : dark,
628628
locs: response['location'],
629629
stars: repos.map(repo => repo['stargazers_count']).reduce((a, b) => a + b),
630630
forks: repos.map(repo => repo['forks_count']).reduce((a, b) => a + b),
@@ -640,11 +640,11 @@ async function getAccount(username, query={}) {
640640
};
641641
}
642642

643-
async function getRepository(username, repo, query={}) {
643+
async function getRepository(username, repo, dark=false) {
644644
// get releases (700ms): (await cache.requestWithCache(`/repos/${username}/${repo}/releases`)).length
645645
const info = await cache.requestWithCache(`/repos/${username}/${repo}`);
646646
return {
647-
dark : query['theme'] === 'dark',
647+
dark : dark,
648648
username: username,
649649
repo: repo,
650650
size: storeConvert(info['size'], 1),

views/error.ejs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<svg width="450" height="195" viewBox="0 0 660 216" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="descId">
2+
<title id="titleId">Error</title>
3+
<desc id="descId">User Code Statistics</desc>
4+
<style>
5+
.header {
6+
font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif;
7+
fill: <%- dark ? "#fff" : "#434d58" %>;
8+
animation: fadeInAnimation 0.8s ease-in-out forwards;
9+
}
10+
@supports(-moz-appearance: auto) {
11+
.header { font-size: 15.5px; }
12+
}
13+
.bold { font-weight: 700 }
14+
#rect-mask rect{
15+
animation: fadeInAnimation 1s ease-in-out forwards;
16+
}
17+
18+
@keyframes fadeInAnimation {
19+
from {
20+
opacity: 0;
21+
}
22+
to {
23+
opacity: 1;
24+
}
25+
}
26+
</style>
27+
<rect data-testid="card-bg" x="0.5" y="0.5" rx="4.5" height="99%" stroke="#e4e2e2" width="659" fill="<%- dark ? "#000" : "#fffefe" %>" stroke-opacity="1"/>
28+
<g data-testid="card-title" transform="translate(200, 108)"><g transform="translate(0, 0)"><text x="0" y="0" class="header" data-testid="header">Sorry, there is something wrong...</text></g></g>
29+
</svg>

0 commit comments

Comments
 (0)