1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-10 12:42:44 +01:00

Try catch handleFile

This commit is contained in:
Madeline 2022-07-22 12:09:52 +10:00
parent 66fc4fb953
commit 94a2d57e90
No known key found for this signature in database
GPG Key ID: 80D25DA3BCB24281

View File

@ -31,7 +31,7 @@ const toDataURL = async (url: string) => {
const blob = await response.blob();
const buffer = Buffer.from(await blob.text());
return `data:${blob.type};base64,${buffer.toString("base64")}`;
}
};
class Discord {
static getAccessToken = async (req: Request, res: Response) => {
@ -126,9 +126,14 @@ app.get("/oauth/:type", async (req, res) => {
});
if (details.avatar_url) {
const avatar = await handleFile(`/avatars/${user.id}`, await toDataURL(details.avatar_url) as string);
user.avatar = avatar;
await user.save();
try {
const avatar = await handleFile(`/avatars/${user.id}`, await toDataURL(details.avatar_url) as string);
user.avatar = avatar;
await user.save();
}
catch (e) {
console.error(e);
}
}
}