diff --git a/config/config.example.toml b/config/config.example.toml index dd075c67..a1bc6345 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -246,10 +246,12 @@ allowed_mime_types = [ visibility = "public" # Default language for new notes (ISO code) language = "en" -# Default avatar, must be a valid URL or "" for none +# Default avatar, must be a valid URL or "" for a placeholder avatar avatar = "" # Default header, must be a valid URL or "" for none header = "" +# A style name from https://www.dicebear.com/styles +placeholder_style = "thumbs" [federation] # This is a list of domain names, such as "mastodon.social" or "pleroma.site" diff --git a/database/entities/User.ts b/database/entities/User.ts index 3f3aa4e7..0e42d084 100644 --- a/database/entities/User.ts +++ b/database/entities/User.ts @@ -34,7 +34,11 @@ export type UserWithRelations = Prisma.UserGetPayload; * @returns The raw URL for the user's avatar */ export const getAvatarUrl = (user: User, config: Config) => { - if (!user.avatar) return config.defaults.avatar; + if (!user.avatar) + return ( + config.defaults.avatar || + `https://api.dicebear.com/8.x/${config.defaults.placeholder_style}/svg?seed=${user.username}` + ); return getUrl(user.avatar, config); }; diff --git a/packages/config-manager/config.type.ts b/packages/config-manager/config.type.ts index 0b004ef5..0d542d93 100644 --- a/packages/config-manager/config.type.ts +++ b/packages/config-manager/config.type.ts @@ -260,6 +260,9 @@ export interface Config { /** @default "" */ header: string; + + /** @default "thumbs" */ + placeholder_style: string; }; federation: { @@ -540,6 +543,7 @@ export const defaultConfig: Config = { language: "en", avatar: "", header: "", + placeholder_style: "thumbs", }, federation: { blocked: [],