github-readme-stats/api/pin.js

35 lines
680 B
JavaScript
Raw Normal View History

2020-07-12 01:50:42 +08:00
require("dotenv").config();
2020-07-12 00:40:13 +08:00
const { renderError } = require("../src/utils");
const fetchRepo = require("../src/fetchRepo");
const renderRepoCard = require("../src/renderRepoCard");
2020-07-10 00:53:14 +08:00
module.exports = async (req, res) => {
const {
username,
repo,
title_color,
icon_color,
text_color,
bg_color,
} = req.query;
2020-07-10 00:53:14 +08:00
2020-07-10 20:42:31 +08:00
let repoData;
2020-07-10 00:53:14 +08:00
res.setHeader("Content-Type", "image/svg+xml");
2020-07-10 20:42:31 +08:00
try {
repoData = await fetchRepo(username, repo);
} catch (err) {
console.log(err);
return res.send(renderError(err.message));
}
res.send(
renderRepoCard(repoData, {
title_color,
icon_color,
text_color,
bg_color,
})
);
2020-07-10 00:53:14 +08:00
};