diff --git a/api/index.js b/api/index.js index 62286a350b5e2..68c34e0d11fab 100644 --- a/api/index.js +++ b/api/index.js @@ -37,32 +37,32 @@ module.exports = async (req, res) => { parseBoolean(count_private), parseBoolean(include_all_commits) ); - } catch (err) { - return res.send(renderError(err.message, err.secondaryMessage)); - } - const cacheSeconds = clampValue( - parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10), - CONSTANTS.TWO_HOURS, - CONSTANTS.ONE_DAY - ); + const cacheSeconds = clampValue( + parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10), + CONSTANTS.TWO_HOURS, + CONSTANTS.ONE_DAY + ); - res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`); + res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`); - res.send( - renderStatsCard(stats, { - hide: parseArray(hide), - show_icons: parseBoolean(show_icons), - hide_title: parseBoolean(hide_title), - hide_border: parseBoolean(hide_border), - hide_rank: parseBoolean(hide_rank), - include_all_commits: parseBoolean(include_all_commits), - line_height, - title_color, - icon_color, - text_color, - bg_color, - theme, - }) - ); + return res.send( + renderStatsCard(stats, { + hide: parseArray(hide), + show_icons: parseBoolean(show_icons), + hide_title: parseBoolean(hide_title), + hide_border: parseBoolean(hide_border), + hide_rank: parseBoolean(hide_rank), + include_all_commits: parseBoolean(include_all_commits), + line_height, + title_color, + icon_color, + text_color, + bg_color, + theme, + }) + ); + } catch (err) { + return res.send(renderError(err.message, err.secondaryMessage)); + } }; diff --git a/api/pin.js b/api/pin.js index a9200619773d1..3fc50584cd181 100644 --- a/api/pin.js +++ b/api/pin.js @@ -27,39 +27,39 @@ module.exports = async (req, res) => { try { repoData = await fetchRepo(username, repo); - } catch (err) { - return res.send(renderError(err.message, err.secondaryMessage)); - } - let cacheSeconds = clampValue( - parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10), - CONSTANTS.TWO_HOURS, - CONSTANTS.ONE_DAY - ); + let cacheSeconds = clampValue( + parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10), + CONSTANTS.TWO_HOURS, + CONSTANTS.ONE_DAY + ); - /* + /* if star count & fork count is over 1k then we are kFormating the text and if both are zero we are not showing the stats so we can just make the cache longer, since there is no need to frequent updates */ - const stars = repoData.stargazers.totalCount; - const forks = repoData.forkCount; - const isBothOver1K = stars > 1000 && forks > 1000; - const isBothUnder1 = stars < 1 && forks < 1; - if (!cache_seconds && (isBothOver1K || isBothUnder1)) { - cacheSeconds = CONSTANTS.FOUR_HOURS; - } + const stars = repoData.stargazers.totalCount; + const forks = repoData.forkCount; + const isBothOver1K = stars > 1000 && forks > 1000; + const isBothUnder1 = stars < 1 && forks < 1; + if (!cache_seconds && (isBothOver1K || isBothUnder1)) { + cacheSeconds = CONSTANTS.FOUR_HOURS; + } - res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`); + res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`); - res.send( - renderRepoCard(repoData, { - title_color, - icon_color, - text_color, - bg_color, - theme, - show_owner: parseBoolean(show_owner), - }) - ); + return res.send( + renderRepoCard(repoData, { + title_color, + icon_color, + text_color, + bg_color, + theme, + show_owner: parseBoolean(show_owner), + }) + ); + } catch (err) { + return res.send(renderError(err.message, err.secondaryMessage)); + } }; diff --git a/api/top-langs.js b/api/top-langs.js index c473bd51910c4..8950158d80a87 100644 --- a/api/top-langs.js +++ b/api/top-langs.js @@ -29,29 +29,29 @@ module.exports = async (req, res) => { try { topLangs = await fetchTopLanguages(username); - } catch (err) { - return res.send(renderError(err.message, err.secondaryMessage)); - } - const cacheSeconds = clampValue( - parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10), - CONSTANTS.TWO_HOURS, - CONSTANTS.ONE_DAY - ); + const cacheSeconds = clampValue( + parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10), + CONSTANTS.TWO_HOURS, + CONSTANTS.ONE_DAY + ); - res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`); + res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`); - res.send( - renderTopLanguages(topLangs, { - hide_title: parseBoolean(hide_title), - hide_border: parseBoolean(hide_border), - card_width: parseInt(card_width, 10), - hide: parseArray(hide), - title_color, - text_color, - bg_color, - theme, - layout, - }) - ); + return res.send( + renderTopLanguages(topLangs, { + hide_title: parseBoolean(hide_title), + hide_border: parseBoolean(hide_border), + card_width: parseInt(card_width, 10), + hide: parseArray(hide), + title_color, + text_color, + bg_color, + theme, + layout, + }) + ); + } catch (err) { + return res.send(renderError(err.message, err.secondaryMessage)); + } };