feat: add DiceBear avatar proxy with style picker on signup and profile pages
Implement avatar generation via local proxy at `/avatar/{style}/{seed}` that fetches from DiceBear 9.x API with in-memory caching and fallback to initial-based SVG. Add avatar style selection dropdown to signup form and profile edit page, storing `avatar_style` in user records. Update comment rendering to support nested threading with parent-child relationships in post view. Add `avatar_url` and `avatar_styles` template globals, register avatar router in main app, and include avatar CSS classes for rounded image display.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
AVATAR_STYLES = [
|
||||
"adventurer",
|
||||
"adventurer-neutral",
|
||||
"avataaars",
|
||||
"big-ears",
|
||||
"big-smile",
|
||||
"bottts",
|
||||
"croodles",
|
||||
"fun-emoji",
|
||||
"identicon",
|
||||
"initials",
|
||||
"lorelei",
|
||||
"micah",
|
||||
"miniavs",
|
||||
"notionists",
|
||||
"open-peeps",
|
||||
"personas",
|
||||
"pixel-art",
|
||||
"shapes",
|
||||
"thumbs",
|
||||
]
|
||||
|
||||
DICEBEAR_BASE = "https://api.dicebear.com/9.x"
|
||||
|
||||
|
||||
def avatar_url(style: str, seed: str, size: int = 128) -> str:
|
||||
style = style or "initials"
|
||||
return f"/avatar/{style}/{seed}?size={size}"
|
||||
|
||||
|
||||
def dicebear_proxy_url(style: str, seed: str, size: int = 128) -> str:
|
||||
return f"{DICEBEAR_BASE}/{style}/svg?seed={seed}&size={size}"
|
||||
|
||||
|
||||
def avatar_styles():
|
||||
return AVATAR_STYLES
|
||||
Reference in New Issue
Block a user