Skip to content

Commit 299eb31

Browse files
committed
SVG improvements
1 parent ce18261 commit 299eb31

File tree

4 files changed

+183
-123
lines changed

4 files changed

+183
-123
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dev": "next dev",
77
"build": "next build",
88
"start": "next start",
9-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
9+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --silent",
1010
"lint": "next lint"
1111
},
1212
"dependencies": {

src/fetcher.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ function fetch_error_handler(fetch, username, last_cache) {
55
return new Promise((resolve, reject) => {
66
const timeoutID = setTimeout(function () {
77
const res = last_cache.get(username);
8-
if (res != null) resolve(res);
8+
if (res != null) {
9+
console.log("Using cached data for", username);
10+
resolve(res);
11+
}
912
else reject({ status: 500, error: "Codeforces Server Error" });
1013
}, 2000);
1114
fetch()
@@ -52,6 +55,7 @@ export function get_rating(username, cache_seconds) {
5255
resolve(res);
5356
})
5457
.catch((error) => {
58+
console.error(error);
5559
if (error.response.status === 400)
5660
reject({ status: 400, error: "Codeforces Handle Not Found" });
5761
else reject({ status: 500, error: "Codeforces Server Error" });
@@ -98,6 +102,7 @@ export function get_stats(username, cache_seconds) {
98102
.replace("undefined", "")
99103
.trim();
100104
const contestsCount = responses[1].data.result.length;
105+
const submissions = responses[2].data.result.length;
101106
const problemsSolved = count_submissions(responses[2].data.result);
102107

103108
const res = {
@@ -109,6 +114,7 @@ export function get_stats(username, cache_seconds) {
109114
maxRank,
110115
contestsCount,
111116
problemsSolved,
117+
submissions,
112118
friendOfCount,
113119
contribution,
114120
};
@@ -117,6 +123,7 @@ export function get_stats(username, cache_seconds) {
117123
resolve(res);
118124
})
119125
.catch((error) => {
126+
console.error(error);
120127
if (error.response.status === 400)
121128
reject({ status: 400, error: "Codeforces Handle Not Found" });
122129
else reject({ status: 500, error: "Codeforces Server Error" });

src/pages/api/card.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import {
77
clamp_value,
88
} from "@/common.js";
99

10-
function check_overflow(rank, maxRank, width) {
11-
return (rank.length + maxRank.length + 8)*10 + 34 > width;
12-
}
13-
1410
export default async function handler(req, res) {
1511
return new Promise((resolve, reject) => {
1612
let {
@@ -51,6 +47,7 @@ export default async function handler(req, res) {
5147
maxRank,
5248
contestsCount,
5349
problemsSolved,
50+
submissions,
5451
friendOfCount,
5552
contribution,
5653
}) => {
@@ -87,9 +84,9 @@ export default async function handler(req, res) {
8784
...themes[theme],
8885
...customColorScheme,
8986
};
90-
const width = Math.max(380, 100 + name.length * 14);
91-
const breakBetweenRank = check_overflow(rank, maxRank, width);
92-
const height = 290 + (breakBetweenRank ? 25 : 0);
87+
const width = Math.max(380, 70 + name.length * 13);
88+
const breakBetweenRank = (rank.length + maxRank.length + 8)*10 + 34 > width;
89+
const height = 290 + (breakBetweenRank ? 22 : 0);
9390

9491
res.send(
9592
renderTemplate("card.svg", {
@@ -103,6 +100,7 @@ export default async function handler(req, res) {
103100
width,
104101
contestsCount,
105102
problemsSolved,
103+
submissions,
106104
friendOfCount,
107105
contribution,
108106
rankColor: get_color_from_rating(rating),

0 commit comments

Comments
 (0)