from __future__ import annotations AVATAR_CROP = "w=480&h=480&fit=crop&crop=faces&auto=format&q=85" # 与 app/data/avatars.ts 保持同步:32 张东亚青年人像 AVATAR_PHOTO_IDS = [ "photo-1534528741775-53994a69daeb", "photo-1542909168-82c3e7fdca5c", "photo-1594744803329-7837a673c588", "photo-1681097561932-36d0df02b379", "photo-1616268164880-673b3ba611bb", "photo-1720501828093-c792c10e3f0b", "photo-1534751516642-a1af1ef26a56", "photo-1542327897-d73f4005b533", "photo-1542996966-2e31c00bae31", "photo-1540569014015-19a7be504e3a", "photo-1696956994811-95c0a29c917c", "photo-1642060603505-e716140d45d2", "photo-1619235327941-c0e47a3ac74a", "photo-1552358155-515e264cb8b8", "photo-1541823709867-1b206113eafd", "photo-1507591064344-4c6ce005b128", "photo-1580489944761-15a19d654956", "photo-1546567850-8a49d669d37a", "photo-1610892417845-07f399a903f4", "photo-1616326431985-b9f89ebc6ab7", "photo-1524502397800-2ee9a7dfd228", "photo-1543610892-0b1f7e6d8ac1", "photo-1573496359142-b8d87734a5a2", "photo-1537107041341-713aaa2a234c", "photo-1601455763557-db1aca8d9a2d", "photo-1503443207922-dff7d543fd0e", "photo-1521577352947-9bb5871b2487", "photo-1534471770828-9bde524ee634", "photo-1544005313-94ddf0286df2", "photo-1563521779750-d0bb67aa1d23", "photo-1554151228-14d9def656e4", "photo-1543132220-3ec99c6094dc", ] AVATAR_URLS = [ f"https://images.unsplash.com/{photo_id}?{AVATAR_CROP}" for photo_id in AVATAR_PHOTO_IDS ] def avatar_for_index(index: int) -> str: return AVATAR_URLS[abs(int(index)) % len(AVATAR_URLS)] def avatar_for_name(name: str) -> str: seed = sum(ord(char) for char in (name or "NomadCNA")) return avatar_for_index(seed)