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
|
|
|
require("dotenv").config();
|
|
|
|
|
|
|
|
module.exports = async (req, res) => {
|
2020-07-11 16:47:51 +08:00
|
|
|
const { username, repo } = 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));
|
|
|
|
}
|
|
|
|
|
2020-07-10 00:53:14 +08:00
|
|
|
res.send(renderRepoCard(repoData));
|
|
|
|
};
|