mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-02 10:58:05 +00:00
UI refinements (#2859)
## Description: UI Refinements requested by @evanpelle check https://ui.openfront.dev ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: w.o.n
This commit is contained in:
@@ -393,3 +393,29 @@ export async function getSvgAspectRatio(src: string): Promise<number | null> {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getDiscordAvatarUrl(user: {
|
||||
id: string;
|
||||
avatar: string | null;
|
||||
discriminator?: string;
|
||||
}): string | null {
|
||||
if (user.avatar) {
|
||||
// - id is a Discord numeric string
|
||||
// - avatar is a hash, optionally prefixed with "a_" for animated avatars
|
||||
const validId = /^\d+$/.test(user.id);
|
||||
const validAvatar =
|
||||
/^[a-f0-9]+$/.test(user.avatar) || /^a_[a-f0-9]+$/.test(user.avatar);
|
||||
|
||||
if (validId && validAvatar) {
|
||||
const extension = user.avatar.startsWith("a_") ? "gif" : "png";
|
||||
return `https://cdn.discordapp.com/avatars/${encodeURIComponent(user.id)}/${encodeURIComponent(user.avatar)}.${extension}?size=64`;
|
||||
}
|
||||
}
|
||||
|
||||
if (user.discriminator !== undefined) {
|
||||
const idx = Number(user.discriminator) % 5;
|
||||
return `https://cdn.discordapp.com/embed/avatars/${idx}.png`;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user