Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions api/gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
setErrorCacheHeaders,
} from "../src/common/cache.js";
import { guardAccess } from "../src/common/access.js";
import { retrieveSecondaryMessage } from "../src/common/error.js";

// @ts-ignore
export default async (req, res) => {
const {
id,
Expand Down Expand Up @@ -89,10 +91,24 @@
);
} catch (err) {
setErrorCacheHeaders(res);
if (err instanceof Error) {
return res.send(
renderError({
message: err.message,
secondaryMessage: retrieveSecondaryMessage(err),
renderOptions: {
title_color,
text_color,
bg_color,
border_color,
theme,
},
}),

Check failure

Code scanning / CodeQL

Reflected cross-site scripting High

Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
);
}
return res.send(
renderError({
message: err.message,
secondaryMessage: err.secondaryMessage,
message: "An unknown error occurred",
renderOptions: {
title_color,
text_color,
Expand Down
20 changes: 18 additions & 2 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
setCacheHeaders,
setErrorCacheHeaders,
} from "../src/common/cache.js";
import { retrieveSecondaryMessage } from "../src/common/error.js";
import { parseArray, parseBoolean, renderError } from "../src/common/utils.js";
import { fetchStats } from "../src/fetchers/stats.js";
import { isLocaleAvailable } from "../src/translations.js";

// @ts-ignore
export default async (req, res) => {
const {
username,
Expand Down Expand Up @@ -127,10 +129,24 @@
);
} catch (err) {
setErrorCacheHeaders(res);
if (err instanceof Error) {
return res.send(
renderError({
message: err.message,
secondaryMessage: retrieveSecondaryMessage(err),
renderOptions: {
title_color,
text_color,
bg_color,
border_color,
theme,
},
}),

Check failure

Code scanning / CodeQL

Reflected cross-site scripting High

Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.

Check warning

Code scanning / CodeQL

Exception text reinterpreted as HTML Medium

Exception text
is reinterpreted as HTML without escaping meta-characters.
);
}
return res.send(
renderError({
message: err.message,
secondaryMessage: err.secondaryMessage,
message: "An unknown error occurred",
renderOptions: {
title_color,
text_color,
Expand Down
20 changes: 18 additions & 2 deletions api/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
setCacheHeaders,
setErrorCacheHeaders,
} from "../src/common/cache.js";
import { retrieveSecondaryMessage } from "../src/common/error.js";
import { parseBoolean, renderError } from "../src/common/utils.js";
import { fetchRepo } from "../src/fetchers/repo.js";
import { isLocaleAvailable } from "../src/translations.js";

// @ts-ignore
export default async (req, res) => {
const {
username,
Expand Down Expand Up @@ -92,10 +94,24 @@
);
} catch (err) {
setErrorCacheHeaders(res);
if (err instanceof Error) {
return res.send(
renderError({
message: err.message,
secondaryMessage: retrieveSecondaryMessage(err),
renderOptions: {
title_color,
text_color,
bg_color,
border_color,
theme,
},
}),

Check failure

Code scanning / CodeQL

Reflected cross-site scripting High

Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.

Check warning

Code scanning / CodeQL

Exception text reinterpreted as HTML Medium

Exception text
is reinterpreted as HTML without escaping meta-characters.
);
}
return res.send(
renderError({
message: err.message,
secondaryMessage: err.secondaryMessage,
message: "An unknown error occurred",
renderOptions: {
title_color,
text_color,
Expand Down
20 changes: 18 additions & 2 deletions api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
setCacheHeaders,
setErrorCacheHeaders,
} from "../src/common/cache.js";
import { retrieveSecondaryMessage } from "../src/common/error.js";
import { parseArray, parseBoolean, renderError } from "../src/common/utils.js";
import { fetchTopLanguages } from "../src/fetchers/top-languages.js";
import { isLocaleAvailable } from "../src/translations.js";

// @ts-ignore
export default async (req, res) => {
const {
username,
Expand Down Expand Up @@ -150,10 +152,24 @@
);
} catch (err) {
setErrorCacheHeaders(res);
if (err instanceof Error) {
return res.send(
renderError({
message: err.message,
secondaryMessage: retrieveSecondaryMessage(err),
renderOptions: {
title_color,
text_color,
bg_color,
border_color,
theme,
},
}),

Check failure

Code scanning / CodeQL

Reflected cross-site scripting High

Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.

Check warning

Code scanning / CodeQL

Exception text reinterpreted as HTML Medium

Exception text
is reinterpreted as HTML without escaping meta-characters.
);
}
return res.send(
renderError({
message: err.message,
secondaryMessage: err.secondaryMessage,
message: "An unknown error occurred",
renderOptions: {
title_color,
text_color,
Expand Down
20 changes: 18 additions & 2 deletions api/wakatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
setErrorCacheHeaders,
} from "../src/common/cache.js";
import { guardAccess } from "../src/common/access.js";
import { retrieveSecondaryMessage } from "../src/common/error.js";

// @ts-ignore
export default async (req, res) => {
const {
username,
Expand Down Expand Up @@ -108,10 +110,24 @@
);
} catch (err) {
setErrorCacheHeaders(res);
if (err instanceof Error) {
return res.send(
renderError({
message: err.message,
secondaryMessage: retrieveSecondaryMessage(err),
renderOptions: {
title_color,
text_color,
bg_color,
border_color,
theme,
},
}),

Check failure

Code scanning / CodeQL

Reflected cross-site scripting High

Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.

Check warning

Code scanning / CodeQL

Exception text reinterpreted as HTML Medium

Exception text
is reinterpreted as HTML without escaping meta-characters.
Exception text
is reinterpreted as HTML without escaping meta-characters.
Exception text
is reinterpreted as HTML without escaping meta-characters.
);
}
return res.send(
renderError({
message: err.message,
secondaryMessage: err.secondaryMessage,
message: "An unknown error occurred",
renderOptions: {
title_color,
text_color,
Expand Down
2 changes: 1 addition & 1 deletion scripts/preview-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Hjson from "hjson";
import snakeCase from "lodash.snakecase";
import parse from "parse-diff";
import { inspect } from "util";
import { isValidHexColor, isValidGradient } from "../src/common/utils.js";
import { isValidHexColor, isValidGradient } from "../src/common/color.js";
import { themes } from "../themes/index.js";
import { getGithubToken, getRepoInfo } from "./helpers.js";

Expand Down
3 changes: 2 additions & 1 deletion src/cards/gist.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @ts-check

import {
getCardColors,
parseEmojis,
wrapTextMultiline,
encodeHTML,
Expand All @@ -12,6 +11,7 @@ import {
createLanguageNode,
} from "../common/utils.js";
import Card from "../common/Card.js";
import { getCardColors } from "../common/color.js";
import { icons } from "../common/icons.js";

/** Import language colors.
Expand Down Expand Up @@ -96,6 +96,7 @@ const renderGistCard = (gistData, options = {}) => {
);

const languageName = language || "Unspecified";
// @ts-ignore
const languageColor = languageColors[languageName] || "#858585";

const svgLanguage = createLanguageNode(languageName, languageColor);
Expand Down
3 changes: 2 additions & 1 deletion src/cards/repo.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// @ts-check

import { Card } from "../common/Card.js";
import { getCardColors } from "../common/color.js";
import { I18n } from "../common/I18n.js";
import { icons } from "../common/icons.js";
import {
encodeHTML,
flexLayout,
getCardColors,
kFormatter,
measureText,
parseEmojis,
Expand Down
29 changes: 17 additions & 12 deletions src/cards/stats.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// @ts-check

import { Card } from "../common/Card.js";
import { getCardColors } from "../common/color.js";
import { CustomError } from "../common/error.js";
import { I18n } from "../common/I18n.js";
import { icons, rankIcon } from "../common/icons.js";
import {
clampValue,
flexLayout,
getCardColors,
kFormatter,
measureText,
} from "../common/utils.js";
Expand Down Expand Up @@ -392,21 +392,24 @@ const renderStatsCard = (stats, options = {}) => {
// filter out hidden stats defined by user & create the text nodes
const statItems = Object.keys(STATS)
.filter((key) => !hide.includes(key))
.map((key, index) =>
.map((key, index) => {
// @ts-ignore
const stats = STATS[key];

// create the text nodes, and pass index so that we can calculate the line spacing
createTextNode({
icon: STATS[key].icon,
label: STATS[key].label,
value: STATS[key].value,
id: STATS[key].id,
unitSymbol: STATS[key].unitSymbol,
return createTextNode({
icon: stats.icon,
label: stats.label,
value: stats.value,
id: stats.id,
unitSymbol: stats.unitSymbol,
index,
showIcons: show_icons,
shiftValuePos: 79.01 + (isLongLocale ? 50 : 0),
bold: text_bold,
number_format,
}),
);
});
});

if (statItems.length === 0 && hide_rank) {
throw new CustomError(
Expand Down Expand Up @@ -541,14 +544,16 @@ const renderStatsCard = (stats, options = {}) => {
const labels = Object.keys(STATS)
.filter((key) => !hide.includes(key))
.map((key) => {
// @ts-ignore
const stats = STATS[key];
if (key === "commits") {
return `${i18n.t("statcard.commits")} ${getTotalCommitsYearLabel(
include_all_commits,
commits_year,
i18n,
)} : ${STATS[key].value}`;
)} : ${stats.value}`;
}
return `${STATS[key].label}: ${STATS[key].value}`;
return `${stats.label}: ${stats.value}`;
})
.join(", ");

Expand Down
5 changes: 4 additions & 1 deletion src/cards/top-languages.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// @ts-check

import { Card } from "../common/Card.js";
import { getCardColors } from "../common/color.js";
import { createProgressNode } from "../common/createProgressNode.js";
import { I18n } from "../common/I18n.js";
import {
chunkArray,
clampValue,
flexLayout,
getCardColors,
lowercaseTrim,
measureText,
formatBytes,
Expand Down Expand Up @@ -180,6 +181,7 @@ const trimTopLanguages = (topLangs, langs_count, hide) => {
// while filtering out
if (hide) {
hide.forEach((langName) => {
// @ts-ignore
langsToHide[lowercaseTrim(langName)] = true;
});
}
Expand All @@ -188,6 +190,7 @@ const trimTopLanguages = (topLangs, langs_count, hide) => {
langs = langs
.sort((a, b) => b.size - a.size)
.filter((lang) => {
// @ts-ignore
return !langsToHide[lowercaseTrim(lang.name)];
})
.slice(0, langsCount);
Expand Down
10 changes: 4 additions & 6 deletions src/cards/wakatime.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// @ts-check

import { Card } from "../common/Card.js";
import { getCardColors } from "../common/color.js";
import { createProgressNode } from "../common/createProgressNode.js";
import { I18n } from "../common/I18n.js";
import {
clampValue,
flexLayout,
getCardColors,
lowercaseTrim,
} from "../common/utils.js";
import { clampValue, flexLayout, lowercaseTrim } from "../common/utils.js";
import { wakatimeCardLocales } from "../translations.js";

/** Import language colors.
Expand Down Expand Up @@ -69,6 +65,7 @@ const formatLanguageValue = ({ display_format, lang }) => {
* @returns {string} The compact layout language SVG node.
*/
const createCompactLangNode = ({ lang, x, y, display_format }) => {
// @ts-ignore
const color = languageColors[lang.name] || "#858585";
const value = formatLanguageValue({ display_format, lang });

Expand Down Expand Up @@ -329,6 +326,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
// const progress = (width * lang.percent) / 100;
const progress = ((width - 25) * language.percent) / 100;

// @ts-ignore
const languageColor = languageColors[language.name] || "#858585";

const output = `
Expand Down
6 changes: 3 additions & 3 deletions src/common/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const resolveCacheSeconds = ({ requested, def, min, max }) => {
/**
* Disables caching by setting appropriate headers on the response object.
*
* @param {Object} res The response object.
* @param {any} res The response object.
*/
const disableCaching = (res) => {
// Disable caching for browsers, shared caches/CDNs, and GitHub Camo.
Expand All @@ -101,7 +101,7 @@ const disableCaching = (res) => {
/**
* Sets the Cache-Control headers on the response object.
*
* @param {Object} res The response object.
* @param {any} res The response object.
* @param {number} cacheSeconds The cache seconds to set in the headers.
*/
const setCacheHeaders = (res, cacheSeconds) => {
Expand All @@ -121,7 +121,7 @@ const setCacheHeaders = (res, cacheSeconds) => {
/**
* Sets the Cache-Control headers for error responses on the response object.
*
* @param {Object} res The response object.
* @param {any} res The response object.
*/
const setErrorCacheHeaders = (res) => {
const envCacheSeconds = process.env.CACHE_SECONDS
Expand Down
Loading
Loading