Skip to content

Commit e7b6f1b

Browse files
authored
Enhance SVG card generation with avatar support
Updated the SVG generation logic to include avatar image in base64 format and improved error handling for input validation.
1 parent 9991109 commit e7b6f1b

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

api/github-card.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ app.get("/api/svg-card/", async (req, res) => {
7474
return res.send(errorSvg);
7575
}
7676

77-
const github = await getGithubData(name)
78-
7977
/* const github = {};
8078
github.name = "Lemon";
8179
github.bio = "About You And Me";
@@ -87,15 +85,28 @@ app.get("/api/svg-card/", async (req, res) => {
8785
github.followers = 47;
8886
*/
8987

88+
const github = await getGithubData(name)
89+
9090
if (!desc) {
9191
desc = github.bio || "No description provided.";
9292
}
9393

94+
// ==========================================
95+
9496
name = github.name.toUpperCase();
9597
desc = `❝ ${desc} ❞`;
9698
desc = wrapSVGText(desc, 50, 17);
9799

100+
const avatarBuffer = await fetch(github.avatar_url)
101+
.then(r => r.arrayBuffer())
102+
.then(buf => Buffer.from(buf));
103+
104+
const avatarBase64 = avatarBuffer.toString("base64");
105+
106+
// ==========================================
107+
98108
const svg = await generateSVG(
109+
avatarBase64,
99110
name,
100111
desc,
101112
age,
@@ -150,5 +161,6 @@ module.exports = app;
150161

151162

152163

164+
153165

154166

0 commit comments

Comments
 (0)