mirror of
https://github.com/Murasame-Dev/McStatus-API.git
synced 2025-12-18 06:07:45 +00:00
chore: move the functions and modules to great place.
This commit is contained in:
parent
d268b6c9fa
commit
20bc7fe826
2 changed files with 27 additions and 26 deletions
2
app.py
2
app.py
|
|
@ -5,6 +5,7 @@
|
||||||
# 基础模块
|
# 基础模块
|
||||||
import asyncio
|
import asyncio
|
||||||
import base64
|
import base64
|
||||||
|
import uvicorn
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
# API
|
# API
|
||||||
|
|
@ -112,5 +113,4 @@ async def get_status_image(ip: str = Query(None, description="服务器IP地址
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import uvicorn
|
|
||||||
uvicorn.run("app:app", host="0.0.0.0", port=5000, reload=True)
|
uvicorn.run("app:app", host="0.0.0.0", port=5000, reload=True)
|
||||||
|
|
@ -18,6 +18,31 @@ from config import BACKGROUND_URL, DEFAULT_ICON, FONT_PATH, IMAGE_WIDTH, IMAGE_H
|
||||||
import base64
|
import base64
|
||||||
import asyncio
|
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):
|
async def get_icon_image(url: str):
|
||||||
if url.startswith("http"):
|
if url.startswith("http"):
|
||||||
icon_data = await download_image_with_httpx_auto_redirect(url)
|
icon_data = await download_image_with_httpx_auto_redirect(url)
|
||||||
|
|
@ -118,27 +143,3 @@ async def generate_bedrock_status_image(addr: str):
|
||||||
font_url,
|
font_url,
|
||||||
image_size)
|
image_size)
|
||||||
return image
|
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
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue