fix: leak of response model.

This commit is contained in:
EstrellaXD
2023-08-13 18:13:25 +08:00
parent 8300461155
commit 6cac596d85
12 changed files with 130 additions and 57 deletions

View File

@@ -1,9 +1,10 @@
import logging
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi import APIRouter, Depends
from fastapi.responses import JSONResponse
from module.conf import settings
from module.models import Config
from module.models import Config, APIResponse
from module.security.api import get_current_user, UNAUTHORIZED
router = APIRouter(prefix="/config", tags=["config"])
@@ -17,7 +18,7 @@ async def get_config(current_user=Depends(get_current_user)):
return settings
@router.patch("/update")
@router.patch("/update", response_model=APIResponse)
async def update_config(config: Config, current_user=Depends(get_current_user)):
if not current_user:
raise UNAUTHORIZED
@@ -26,7 +27,13 @@ async def update_config(config: Config, current_user=Depends(get_current_user)):
settings.load()
# update_rss()
logger.info("Config updated")
return {"message": "Success"}
return JSONResponse(
status_code=200,
content={"msg_en": "Update config successfully.", "msg_zh": "更新配置成功。"}
)
except Exception as e:
logger.warning(e)
return {"message": "Failed to update config"}
return JSONResponse(
status_code=406,
content={"msg_en": "Update config failed.", "msg_zh": "更新配置失败。"}
)