hotfix for images hosted elsewhere and link stored in DB (#1480)
* hotfix for images hosted elsewhere and link stored in DB * improved if else Co-authored-by: Peer Richelsen <peeroke@gmail.com>pull/1475/head
parent
d2b9e67424
commit
ac6275b906
|
@ -22,7 +22,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
.update(user?.email as string)
|
.update(user?.email as string)
|
||||||
.digest("hex");
|
.digest("hex");
|
||||||
const img = user?.avatar;
|
const img = user?.avatar;
|
||||||
if (img) {
|
if (!img) {
|
||||||
|
res.writeHead(302, {
|
||||||
|
Location: defaultAvatarSrc({ md5: emailMd5 }),
|
||||||
|
});
|
||||||
|
res.end();
|
||||||
|
} else if (!img.includes("data:image")) {
|
||||||
|
res.writeHead(302, {
|
||||||
|
Location: img,
|
||||||
|
});
|
||||||
|
res.end();
|
||||||
|
} else {
|
||||||
const decoded = img
|
const decoded = img
|
||||||
.toString()
|
.toString()
|
||||||
.replace("data:image/png;base64,", "")
|
.replace("data:image/png;base64,", "")
|
||||||
|
@ -33,10 +43,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
"Content-Length": imageResp.length,
|
"Content-Length": imageResp.length,
|
||||||
});
|
});
|
||||||
res.end(imageResp);
|
res.end(imageResp);
|
||||||
} else {
|
|
||||||
res.writeHead(302, {
|
|
||||||
Location: defaultAvatarSrc({ md5: emailMd5 }),
|
|
||||||
});
|
|
||||||
res.end();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue