) {
<>
{isReady && (
diff --git a/pages/api/user/avatar.ts b/pages/api/user/avatar.ts
new file mode 100644
index 00000000..550723fc
--- /dev/null
+++ b/pages/api/user/avatar.ts
@@ -0,0 +1,42 @@
+import crypto from "crypto";
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import prisma from "@lib/prisma";
+import { defaultAvatarSrc } from "@lib/profile";
+
+export default async function handler(req: NextApiRequest, res: NextApiResponse) {
+ // const username = req.url?.substring(1, req.url.lastIndexOf("/"));
+ const username = req.query.username as string;
+ const user = await prisma.user.findUnique({
+ where: {
+ username: username,
+ },
+ select: {
+ avatar: true,
+ email: true,
+ },
+ });
+
+ const emailMd5 = crypto
+ .createHash("md5")
+ .update(user?.email as string)
+ .digest("hex");
+ const img = user?.avatar;
+ if (img) {
+ const decoded = img
+ .toString()
+ .replace("data:image/png;base64,", "")
+ .replace("data:image/jpeg;base64,", "");
+ const imageResp = Buffer.from(decoded, "base64");
+ res.writeHead(200, {
+ "Content-Type": "image/png",
+ "Content-Length": imageResp.length,
+ });
+ res.end(imageResp);
+ } else {
+ res.writeHead(302, {
+ Location: defaultAvatarSrc({ md5: emailMd5 }),
+ });
+ res.end();
+ }
+}
diff --git a/pages/settings/profile.tsx b/pages/settings/profile.tsx
index 767cf01a..54e0f3c4 100644
--- a/pages/settings/profile.tsx
+++ b/pages/settings/profile.tsx
@@ -220,7 +220,6 @@ function SettingsView(props: ComponentProps & { localeProp: str
/>
-