perchitis
This commit is contained in:
parent
dfaab3a290
commit
d6f21728da
|
@ -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") {
|
if (avatarBase64 !== null && typeof avatarBase64 === "string") {
|
||||||
avatarBuf = Buffer.from(avatarBase64, "base64");
|
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);
|
await ldap.setPassword(username, password);
|
||||||
|
|
||||||
const outputUser = await prisma.user.update({
|
const outputUser = await prisma.user.update({
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { getLogger } from "@/logger";
|
||||||
type RequestBody = {
|
type RequestBody = {
|
||||||
displayName?: string;
|
displayName?: string;
|
||||||
email?: string;
|
email?: string;
|
||||||
avatarBase64?: string;
|
avatar?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
|
@ -20,8 +20,11 @@ export async function POST(request: Request) {
|
||||||
return new Response(null, { status: 409 });
|
return new Response(null, { status: 409 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const { displayName, email, avatarBase64 } =
|
const {
|
||||||
(await request.json()) as RequestBody;
|
displayName,
|
||||||
|
email,
|
||||||
|
avatar: avatarBase64
|
||||||
|
} = (await request.json()) as RequestBody;
|
||||||
|
|
||||||
let changeDisplayName = false;
|
let changeDisplayName = false;
|
||||||
if (
|
if (
|
||||||
|
@ -77,7 +80,7 @@ export async function POST(request: Request) {
|
||||||
username: user.username,
|
username: user.username,
|
||||||
displayName: changeDisplayName ? displayName : null,
|
displayName: changeDisplayName ? displayName : null,
|
||||||
email: changeEmail ? email : null,
|
email: changeEmail ? email : null,
|
||||||
avatar: avatarBuf ? avatarBuf.toString("base64") : null
|
avatar: avatarBuf ? `${avatarBuf.length} bytes` : null
|
||||||
},
|
},
|
||||||
"updated user"
|
"updated user"
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,7 +10,7 @@ export type DiscordAccessTokenResponse = {
|
||||||
|
|
||||||
export type DiscordUserResponse = {
|
export type DiscordUserResponse = {
|
||||||
id: string;
|
id: string;
|
||||||
avatar: string;
|
avatar: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DiscordGuildResponse = {
|
export type DiscordGuildResponse = {
|
||||||
|
@ -49,6 +49,7 @@ export async function getDiscordAvatar(token: string) {
|
||||||
});
|
});
|
||||||
|
|
||||||
const res: DiscordUserResponse = await req.json();
|
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 file = `https://cdn.discordapp.com/avatars/${res.id}/${res.avatar}.png`;
|
||||||
|
|
||||||
const avatarReq = await fetch(file);
|
const avatarReq = await fetch(file);
|
||||||
|
|
Loading…
Reference in New Issue