2023-10-24 10:07:26 +02:00
|
|
|
import { createHash } from 'crypto';
|
2022-11-10 12:13:45 +01:00
|
|
|
|
2023-10-24 10:07:26 +02:00
|
|
|
const base: string = 'https://gravatar.com/avatar';
|
2022-11-10 12:13:45 +01:00
|
|
|
export const generateImageUrl = (user: {
|
2023-10-24 10:07:26 +02:00
|
|
|
email?: string;
|
|
|
|
username?: string;
|
|
|
|
id?: number;
|
|
|
|
}): string => {
|
|
|
|
let ident = user.email || user.username || String(user.id);
|
|
|
|
if (ident.indexOf('@')) {
|
|
|
|
ident = ident.toLowerCase().trim();
|
|
|
|
} else {
|
|
|
|
ident = ident.trim();
|
|
|
|
}
|
|
|
|
const identHash = createHash('sha256').update(ident).digest('hex');
|
|
|
|
return `${base}/${identHash}?s=42&d=retro&r=g`;
|
|
|
|
};
|