Cal 710 turn dataimagejpegbase64 avatar into (#1429)
* --wip * added next-config custom header path * added avatar endpoint * cleanup --wip * adding gravatar fallback support --wip * added endpoint rewrite and avatar access * gravatar support added * build err fix * updated HeadSEO with new avatar logic * --wip * adds og compat * added truncated bio * cleanup * changed truncate of body from 24 chars to 32 chars * removed unused, commented code * removed trailing whitespace * requested changes Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
1 parent
f0abf47ecc
commit
e24d8889fc
5 files changed
+77
-14
No files matched your search
+3
-2
@@ -29,9 +29,10 @@ export default function User(props: inferSSRProps<typeof getServerSideProps>) {
|
||||
<>
|
||||
<HeadSeo
|
||||
title={nameOrUsername}
|
||||
description={nameOrUsername}
|
||||
description={(user.bio as string) || ""}
|
||||
name={nameOrUsername}
|
||||
avatar={user.avatar || undefined}
|
||||
username={(user.username as string) || ""}
|
||||
// avatar={user.avatar || undefined}
|
||||
/>
|
||||
{isReady && (
|
||||
<div className="h-screen bg-neutral-50 dark:bg-black">
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,6 @@ function SettingsView(props: ComponentProps<typeof Settings> & { localeProp: str
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="block sm:flex">
|
||||
<div className="w-full mb-6 sm:w-1/2 sm:mr-2">
|
||||
<label htmlFor="email" className="block text-sm font-medium text-gray-700">
|
||||
|
||||
Reference in new issue
Block a user