Skip to content
Open
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
44 changes: 29 additions & 15 deletions api/gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,27 @@ export default async (req, res) => {
border_color,
show_owner,
hide_border,
json,
} = req.query;

res.setHeader("Content-Type", "image/svg+xml");
const returnJson = parseBoolean(json);

res.setHeader(
"Content-Type",
returnJson ? "application/json" : "image/svg+xml",
);

if (locale && !isLocaleAvailable(locale)) {
return res.send(
renderError("Something went wrong", "Language not found", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
returnJson
? { error: "Language not found" }
: renderError("Something went wrong", "Language not found", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
}

Expand All @@ -55,6 +63,10 @@ export default async (req, res) => {
`max-age=${cacheSeconds}, s-maxage=${cacheSeconds}`,
);

if (returnJson) {
return res.send(gistData);
}

return res.send(
renderGistCard(gistData, {
title_color,
Expand All @@ -77,13 +89,15 @@ export default async (req, res) => {
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
); // Use lower cache period for errors.
return res.send(
renderError(err.message, err.secondaryMessage, {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
returnJson
? { error: err.message, secondaryMessage: err.secondaryMessage }
: renderError(err.message, err.secondaryMessage, {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
}
};
61 changes: 39 additions & 22 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,41 @@ export default async (req, res) => {
border_color,
rank_icon,
show,
json,
} = req.query;
res.setHeader("Content-Type", "image/svg+xml");

const returnJson = parseBoolean(json);

res.setHeader(
"Content-Type",
returnJson ? "application/json" : "image/svg+xml",
);

if (blacklist.includes(username)) {
return res.send(
renderError("Something went wrong", "This username is blacklisted", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
returnJson
? { error: "This username is blacklisted" }
: renderError("Something went wrong", "This username is blacklisted", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
}

if (locale && !isLocaleAvailable(locale)) {
return res.send(
renderError("Something went wrong", "Language not found", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
returnJson
? { error: "Language not found" }
: renderError("Something went wrong", "Language not found", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
}

Expand Down Expand Up @@ -91,6 +102,10 @@ export default async (req, res) => {
`max-age=${cacheSeconds}, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
);

if (returnJson) {
return res.send(stats);
}

return res.send(
renderStatsCard(stats, {
hide: parseArray(hide),
Expand Down Expand Up @@ -126,13 +141,15 @@ export default async (req, res) => {
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
); // Use lower cache period for errors.
return res.send(
renderError(err.message, err.secondaryMessage, {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
returnJson
? { error: err.message, secondaryMessage: err.secondaryMessage }
: renderError(err.message, err.secondaryMessage, {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
}
};
60 changes: 38 additions & 22 deletions api/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,41 @@ export default async (req, res) => {
border_radius,
border_color,
description_lines_count,
json,
} = req.query;

res.setHeader("Content-Type", "image/svg+xml");
const returnJson = parseBoolean(json);

res.setHeader(
"Content-Type",
returnJson ? "application/json" : "image/svg+xml",
);

if (blacklist.includes(username)) {
return res.send(
renderError("Something went wrong", "This username is blacklisted", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
returnJson
? { error: "This username is blacklisted" }
: renderError("Something went wrong", "This username is blacklisted", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
}

if (locale && !isLocaleAvailable(locale)) {
return res.send(
renderError("Something went wrong", "Language not found", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
returnJson
? { error: "Language not found" }
: renderError("Something went wrong", "Language not found", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
}

Expand All @@ -70,6 +80,10 @@ export default async (req, res) => {
`max-age=${cacheSeconds}, s-maxage=${cacheSeconds}`,
);

if (returnJson) {
return res.send(repoData);
}

return res.send(
renderRepoCard(repoData, {
hide_border: parseBoolean(hide_border),
Expand All @@ -93,13 +107,15 @@ export default async (req, res) => {
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
); // Use lower cache period for errors.
return res.send(
renderError(err.message, err.secondaryMessage, {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
returnJson
? { error: err.message, secondaryMessage: err.secondaryMessage }
: renderError(err.message, err.secondaryMessage, {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
}
};
55 changes: 38 additions & 17 deletions api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,36 @@ export default async (req, res) => {
border_color,
disable_animations,
hide_progress,
json,
} = req.query;
res.setHeader("Content-Type", "image/svg+xml");

const returnJson = parseBoolean(json);

res.setHeader(
"Content-Type",
returnJson ? "application/json" : "image/svg+xml",
);

if (blacklist.includes(username)) {
return res.send(
renderError("Something went wrong", "This username is blacklisted", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
returnJson
? { error: "This username is blacklisted" }
: renderError("Something went wrong", "This username is blacklisted", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
}

if (locale && !isLocaleAvailable(locale)) {
return res.send(renderError("Something went wrong", "Locale not found"));
return res.send(
returnJson
? { error: "Locale not found" }
: renderError("Something went wrong", "Locale not found"),
);
}

if (
Expand All @@ -57,7 +70,9 @@ export default async (req, res) => {
!["compact", "normal", "donut", "donut-vertical", "pie"].includes(layout))
) {
return res.send(
renderError("Something went wrong", "Incorrect layout input"),
returnJson
? { error: "Incorrect layout input" }
: renderError("Something went wrong", "Incorrect layout input"),
);
}

Expand All @@ -82,6 +97,10 @@ export default async (req, res) => {
`max-age=${cacheSeconds / 2}, s-maxage=${cacheSeconds}`,
);

if (returnJson) {
return res.send(topLangs);
}

return res.send(
renderTopLanguages(topLangs, {
custom_title,
Expand Down Expand Up @@ -110,13 +129,15 @@ export default async (req, res) => {
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
); // Use lower cache period for errors.
return res.send(
renderError(err.message, err.secondaryMessage, {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
returnJson
? { error: err.message, secondaryMessage: err.secondaryMessage }
: renderError(err.message, err.secondaryMessage, {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
}
};
Loading