fix: query param booleans

This commit is contained in:
anuraghazra 2020-07-15 18:32:16 +05:30
parent 00ce9d37d2
commit 5fce46d67c
2 changed files with 15 additions and 4 deletions

View File

@ -1,5 +1,5 @@
require("dotenv").config();
const { renderError } = require("../src/utils");
const { renderError, parseBoolean } = require("../src/utils");
const fetchStats = require("../src/fetchStats");
const renderStatsCard = require("../src/renderStatsCard");
@ -30,9 +30,9 @@ module.exports = async (req, res) => {
res.send(
renderStatsCard(stats, {
hide: JSON.parse(hide || "[]"),
show_icons,
hide_border,
hide_rank,
show_icons: parseBoolean(show_icons),
hide_border: parseBoolean(hide_border),
hide_rank: parseBoolean(hide_rank),
line_height,
title_color,
icon_color,

View File

@ -33,6 +33,16 @@ function isValidHexColor(hexColor) {
).test(hexColor);
}
function parseBoolean(value) {
if (value === "true") {
return true;
} else if (value === "false") {
return false;
} else {
return value;
}
}
function request(data, headers) {
return new Promise((resolve, reject) => {
axios({
@ -54,4 +64,5 @@ module.exports = {
encodeHTML,
isValidHexColor,
request,
parseBoolean,
};