This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Telegram/api_avatars.py

18 lines
855 B
Python
Raw Normal View History

2022-10-26 16:20:23 +03:00
from os import path, sep
from fastapi import FastAPI, HTTPException
2022-11-04 14:05:14 +02:00
from fastapi.responses import FileResponse, JSONResponse
2022-10-26 16:20:23 +03:00
from starlette.status import HTTP_404_NOT_FOUND
from modules.utils import configGet
app = FastAPI(title="HoloUA Avatars API", docs_url=None, redoc_url=None, version="1.0")
2022-11-04 14:05:14 +02:00
@app.get("/check", response_class=JSONResponse, include_in_schema=False)
async def check():
return JSONResponse({"detail": "I'm alright, thank you"})
2022-10-26 16:20:23 +03:00
@app.get("/", response_class=FileResponse, include_in_schema=False)
async def favicon(avatar_id: str):
if path.exists(f'{configGet("cache", "locations")}{sep}avatars{sep}{avatar_id}'):
2022-10-27 12:40:15 +03:00
return FileResponse(f'{configGet("cache", "locations")}{sep}avatars{sep}{avatar_id}', media_type="image/jpg")
2022-10-26 16:20:23 +03:00
else:
raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail="File not found")