17 lines
610 B
TypeScript
17 lines
610 B
TypeScript
export const AVATAR_BASE_URL = "https://minio.nomadro.cn/hackrobot/nomadcna/avatars";
|
|
|
|
export const AVATAR_URLS = Array.from(
|
|
{ length: 32 },
|
|
(_, index) => `${AVATAR_BASE_URL}/avatar-${String(index + 1).padStart(2, "0")}.jpg`
|
|
);
|
|
|
|
export function avatarForIndex(index: number): string {
|
|
const safeIndex = Number.isFinite(index) ? Math.abs(Math.trunc(index)) : 0;
|
|
return AVATAR_URLS[safeIndex % AVATAR_URLS.length];
|
|
}
|
|
|
|
export function avatarForName(name: string): string {
|
|
const seed = Array.from(name || "NomadCNA").reduce((sum, char) => sum + char.charCodeAt(0), 0);
|
|
return avatarForIndex(seed);
|
|
}
|