From 46c4292c3e7c8988fc07a1cd39bf8c59bc510300 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Thu, 14 Sep 2023 23:19:44 +0800 Subject: [PATCH] fix ghost avatar --- main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index d2ab3e5..c4e5c25 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,5 @@ +from typing import Union + from fastapi import FastAPI from httpx import AsyncClient from starlette.middleware.cors import CORSMiddleware @@ -8,6 +10,7 @@ from starlette.staticfiles import StaticFiles app = FastAPI() local_api = "http://127.0.0.1:9008/luoxu/" local_stats_api = "http://127.0.0.1:9010/api/" +ghost_url = "https://search-pub.xtaolabs.com/luoxu/avatar/ghost.jpg" allowed_origins = [ "search-pub.xtaolabs.com", "127.0.0.1:9009", @@ -72,9 +75,11 @@ async def get_names(request: Request): @app.get("/luoxu/avatar/{avatar}") -async def read_avatar(avatar: str) -> StreamingResponse: +async def read_avatar(avatar: str): async with AsyncClient(timeout=60) as client: r = await client.get(f"{local_api}avatar/{avatar}") + if r.status_code: + return RedirectResponse(url=ghost_url) return StreamingResponse(r.aiter_bytes(), media_type="image/png")