import { createHash } from 'crypto' import randomColor from 'randomcolor' import { config } from './config' // core export function generateAvatar (name: string): string { const color = randomColor({ seed: name, luminosity: 'dark' }) const letter = name.substring(0, 1).toUpperCase() let svg = '' svg += '' svg += '' svg += '' svg += '' svg += '' + letter + '' svg += '' svg += '' svg += '' return svg } export function generateAvatarURL (name: string, email = '', big = true): string { let photo name = encodeURIComponent(name) const hash = createHash('md5') hash.update(email.toLowerCase()) const hexDigest = hash.digest('hex') if (email !== '' && config.allowGravatar) { photo = 'https://cdn.libravatar.org/avatar/' + hexDigest if (big) { photo += '?s=400' } else { photo += '?s=96' } } else { photo = config.serverURL + '/user/' + (name || email.substring(0, email.lastIndexOf('@')) || hexDigest) + '/avatar.svg' } return photo }