perchitis

This commit is contained in:
Julian 2023-04-26 14:38:03 -04:00
parent dfaab3a290
commit d6f21728da
Signed by: NotNite
GPG key ID: BD91A5402CCEB08A
3 changed files with 11 additions and 7 deletions

View file

@ -74,7 +74,7 @@ export async function POST(request: Request) {
);
}
let avatarBuf: Buffer | undefined;
let avatarBuf: Buffer | null | undefined;
if (avatarBase64 !== null && typeof avatarBase64 === "string") {
avatarBuf = Buffer.from(avatarBase64, "base64");
@ -112,7 +112,7 @@ export async function POST(request: Request) {
}
}
await ldap.createUser(username, displayName, email, avatarBuf);
await ldap.createUser(username, displayName, email, avatarBuf ?? undefined);
await ldap.setPassword(username, password);
const outputUser = await prisma.user.update({

View file

@ -5,7 +5,7 @@ import { getLogger } from "@/logger";
type RequestBody = {
displayName?: string;
email?: string;
avatarBase64?: string;
avatar?: string;
};
export async function POST(request: Request) {
@ -20,8 +20,11 @@ export async function POST(request: Request) {
return new Response(null, { status: 409 });
}
const { displayName, email, avatarBase64 } =
(await request.json()) as RequestBody;
const {
displayName,
email,
avatar: avatarBase64
} = (await request.json()) as RequestBody;
let changeDisplayName = false;
if (
@ -77,7 +80,7 @@ export async function POST(request: Request) {
username: user.username,
displayName: changeDisplayName ? displayName : null,
email: changeEmail ? email : null,
avatar: avatarBuf ? avatarBuf.toString("base64") : null
avatar: avatarBuf ? `${avatarBuf.length} bytes` : null
},
"updated user"
);

View file

@ -10,7 +10,7 @@ export type DiscordAccessTokenResponse = {
export type DiscordUserResponse = {
id: string;
avatar: string;
avatar: string | null;
};
export type DiscordGuildResponse = {
@ -49,6 +49,7 @@ export async function getDiscordAvatar(token: string) {
});
const res: DiscordUserResponse = await req.json();
if (res.avatar === null) return null;
const file = `https://cdn.discordapp.com/avatars/${res.id}/${res.avatar}.png`;
const avatarReq = await fetch(file);