Files
github-readme-stats/api/wakatime.js
T
Nathan Chu 057ff69ac2 feat: custom card title (#293)
* Custom stats title (anuraghazra#229)

* Add custom title test

* remove unused code

* Update readme.md to include the `custom_title` option

* Update readme_es.md to include `custom_title` option

Co-Authored-By: José Javier Rodríguez Zas <jjavierdguezas@gmail.com>

* Merge branch 'master' of https://github.com/anuraghazra/github-readme-stats.git into custom-title

* feat: added customTitle option in Card

Co-authored-by: José Javier Rodríguez Zas <jjavierdguezas@gmail.com>
Co-authored-by: Anurag <hazru.anurag@gmail.com>
2020-09-27 13:10:39 +05:30

62 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,
custom_title,
} = 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, {
custom_title,
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));
}
};