feat: replace DiceBear avatar proxy with local Multiavatar SVG generation and remove avatar_style from signup
This commit is contained in:
+14
-31
@@ -2,39 +2,22 @@ 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
|
||||
def generate_avatar_svg(seed: str) -> str:
|
||||
try:
|
||||
from multiavatar import multiavatar
|
||||
svg = multiavatar(seed)
|
||||
if svg and svg.strip().startswith("<svg"):
|
||||
return svg
|
||||
except Exception as e:
|
||||
logger.warning(f"Avatar generation failed for {seed}: {e}")
|
||||
initial = seed[:1].upper() if seed else "?"
|
||||
return (
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">'
|
||||
f'<rect width="100" height="100" rx="50" fill="#ff6b35"/>'
|
||||
f'<text x="50" y="65" text-anchor="middle" fill="white" font-size="40" font-weight="700" font-family="sans-serif">{initial}</text></svg>'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user