2020-07-12 01:50:42 +08:00
|
|
|
require("dotenv").config();
|
2020-07-21 00:13:51 +08:00
|
|
|
const {
|
|
|
|
renderError,
|
|
|
|
parseBoolean,
|
2020-07-23 23:31:23 +08:00
|
|
|
parseArray,
|
2020-07-21 00:13:51 +08:00
|
|
|
clampValue,
|
|
|
|
CONSTANTS,
|
|
|
|
} = require("../src/utils");
|
2020-07-12 00:40:13 +08:00
|
|
|
const fetchStats = require("../src/fetchStats");
|
|
|
|
const renderStatsCard = require("../src/renderStatsCard");
|
2020-07-09 20:20:15 +08:00
|
|
|
|
2020-07-09 18:33:41 +08:00
|
|
|
module.exports = async (req, res) => {
|
2020-07-12 03:01:44 +08:00
|
|
|
const {
|
|
|
|
username,
|
|
|
|
hide,
|
2020-07-18 01:31:16 +08:00
|
|
|
hide_title,
|
2020-07-12 03:01:44 +08:00
|
|
|
hide_border,
|
2020-07-13 22:11:47 +08:00
|
|
|
hide_rank,
|
2020-07-12 03:01:44 +08:00
|
|
|
show_icons,
|
2020-07-24 22:04:38 +08:00
|
|
|
count_private,
|
2020-07-12 03:01:44 +08:00
|
|
|
line_height,
|
|
|
|
title_color,
|
|
|
|
icon_color,
|
|
|
|
text_color,
|
2020-07-12 15:16:08 +08:00
|
|
|
bg_color,
|
2020-07-19 23:04:41 +08:00
|
|
|
theme,
|
2020-07-21 00:13:51 +08:00
|
|
|
cache_seconds,
|
2020-07-12 03:01:44 +08:00
|
|
|
} = req.query;
|
2020-07-10 20:42:31 +08:00
|
|
|
let stats;
|
2020-07-09 18:33:41 +08:00
|
|
|
|
|
|
|
res.setHeader("Content-Type", "image/svg+xml");
|
2020-07-15 17:29:25 +08:00
|
|
|
|
2020-07-10 20:42:31 +08:00
|
|
|
try {
|
2020-07-24 22:04:38 +08:00
|
|
|
stats = await fetchStats(username, parseBoolean(count_private));
|
2020-07-10 20:42:31 +08:00
|
|
|
} catch (err) {
|
|
|
|
return res.send(renderError(err.message));
|
|
|
|
}
|
|
|
|
|
2020-07-21 00:13:51 +08:00
|
|
|
const cacheSeconds = clampValue(
|
|
|
|
parseInt(cache_seconds || CONSTANTS.THIRTY_MINUTES, 10),
|
|
|
|
CONSTANTS.THIRTY_MINUTES,
|
|
|
|
CONSTANTS.ONE_DAY
|
|
|
|
);
|
|
|
|
|
|
|
|
res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
|
|
|
|
|
2020-07-09 20:20:15 +08:00
|
|
|
res.send(
|
2020-07-12 00:40:13 +08:00
|
|
|
renderStatsCard(stats, {
|
2020-07-23 23:31:23 +08:00
|
|
|
hide: parseArray(hide),
|
2020-07-15 21:02:16 +08:00
|
|
|
show_icons: parseBoolean(show_icons),
|
2020-07-18 01:31:16 +08:00
|
|
|
hide_title: parseBoolean(hide_title),
|
2020-07-15 21:02:16 +08:00
|
|
|
hide_border: parseBoolean(hide_border),
|
|
|
|
hide_rank: parseBoolean(hide_rank),
|
2020-07-09 23:59:50 +08:00
|
|
|
line_height,
|
2020-07-12 03:01:44 +08:00
|
|
|
title_color,
|
|
|
|
icon_color,
|
|
|
|
text_color,
|
2020-07-12 15:16:08 +08:00
|
|
|
bg_color,
|
2020-07-19 23:04:41 +08:00
|
|
|
theme,
|
2020-07-09 23:59:50 +08:00
|
|
|
})
|
2020-07-09 20:20:15 +08:00
|
|
|
);
|
2020-07-09 18:33:41 +08:00
|
|
|
};
|