github-readme-stats/api/wakatime.js
Bas950 8aea1e3c35
feat: added repo card hide border option (#488)
* 🚀 Prettier config

* 🚀 hide_border for Repo Card

* fix: wrong total commits (#490)

* chore: run prettier on all files

* chore: lol lets add the trailing commas

Co-authored-by: Anurag Hazra <hazru.anurag@gmail.com>
2020-09-24 21:38:14 +05:30

59 lines
1.3 KiB
JavaScript

require("dotenv").config();
const {
renderError,
parseBoolean,
clampValue,
CONSTANTS,
} = require("../src/common/utils");
const { fetchLast7Days } = require("../src/fetchers/wakatime-fetcher");
const wakatimeCard = require("../src/cards/wakatime-card");
module.exports = async (req, res) => {
const {
username,
title_color,
icon_color,
hide_border,
line_height,
text_color,
bg_color,
theme,
cache_seconds,
hide_title,
hide_progress,
} = req.query;
res.setHeader("Content-Type", "image/svg+xml");
try {
const last7Days = await fetchLast7Days({ username });
let cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
CONSTANTS.TWO_HOURS,
CONSTANTS.ONE_DAY,
);
if (!cache_seconds) {
cacheSeconds = CONSTANTS.FOUR_HOURS;
}
res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
return res.send(
wakatimeCard(last7Days, {
hide_title: parseBoolean(hide_title),
hide_border: parseBoolean(hide_border),
line_height,
title_color,
icon_color,
text_color,
bg_color,
theme,
hide_progress,
}),
);
} catch (err) {
return res.send(renderError(err.message, err.secondaryMessage));
}
};