diff --git a/app.py b/app.py index ee4ece0..9082b0e 100644 --- a/app.py +++ b/app.py @@ -5,6 +5,7 @@ # 基础模块 import asyncio import base64 +import uvicorn from io import BytesIO # API @@ -112,5 +113,4 @@ async def get_status_image(ip: str = Query(None, description="服务器IP地址 raise HTTPException(status_code=500, detail=str(e)) if __name__ == '__main__': - import uvicorn uvicorn.run("app:app", host="0.0.0.0", port=5000, reload=True) \ No newline at end of file diff --git a/generate_img.py b/generate_img.py index be6111d..143f208 100644 --- a/generate_img.py +++ b/generate_img.py @@ -18,6 +18,31 @@ from config import BACKGROUND_URL, DEFAULT_ICON, FONT_PATH, IMAGE_WIDTH, IMAGE_H import base64 import asyncio +async def get_font_url(): + if not FONT_PATH: + font_url = None + else: + font_url = FONT_PATH + return font_url + +async def get_image_size(): + if not IMAGE_WIDTH or not IMAGE_HEIGHT: + image_size = [0,0] + else: + image_size = [IMAGE_WIDTH, IMAGE_HEIGHT] + return image_size + +async def get_background_image(): + if BACKGROUND_URL.startswith("http://") or BACKGROUND_URL.startswith("https://"): + background_data = await download_image_with_httpx_auto_redirect(BACKGROUND_URL) + elif BACKGROUND_URL == "": + background_data = None + else: + with open(BACKGROUND_URL, "rb") as f: + background_data = f.read() + return background_data + + async def get_icon_image(url: str): if url.startswith("http"): icon_data = await download_image_with_httpx_auto_redirect(url) @@ -117,28 +142,4 @@ async def generate_bedrock_status_image(addr: str): motd_list, font_url, image_size) - return image - -async def get_background_image(): - if BACKGROUND_URL.startswith("http://") or BACKGROUND_URL.startswith("https://"): - background_data = await download_image_with_httpx_auto_redirect(BACKGROUND_URL) - elif BACKGROUND_URL == "": - background_data = None - else: - with open(BACKGROUND_URL, "rb") as f: - background_data = f.read() - return background_data - -async def get_font_url(): - if not FONT_PATH: - font_url = None - else: - font_url = FONT_PATH - return font_url - -async def get_image_size(): - if not IMAGE_WIDTH or not IMAGE_HEIGHT: - image_size = [0,0] - else: - image_size = [IMAGE_WIDTH, IMAGE_HEIGHT] - return image_size \ No newline at end of file + return image \ No newline at end of file