refactor: refactor folder as 3.1

This commit is contained in:
EstrellaXD
2023-06-28 16:15:17 +08:00
parent 4c94a51d57
commit 58bff6cbdc
101 changed files with 252 additions and 115 deletions

View File

@@ -0,0 +1,34 @@
import os
from fastapi import Response, HTTPException, Depends, status
from .auth import router
from module.conf import LOG_PATH
from module.security import get_current_user
@router.get("/api/v1/log", tags=["log"])
async def get_log(current_user=Depends(get_current_user)):
if not current_user:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid token"
)
if os.path.isfile(LOG_PATH):
with open(LOG_PATH, "rb") as f:
return Response(f.read(), media_type="text/plain")
else:
return Response("Log file not found", status_code=404)
@router.get("/api/v1/log/clear", tags=["log"])
async def clear_log(current_user=Depends(get_current_user)):
if not current_user:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid token"
)
if os.path.isfile(LOG_PATH):
with open(LOG_PATH, "w") as f:
f.write("")
return {"status": "ok"}
else:
return Response("Log file not found", status_code=404)