File size: 1,678 Bytes
8cdca00 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import os
from fastapi import APIRouter, Depends, HTTPException
from app.core.auth import verify_app_key
from app.core.config import config
from app.core.storage import get_storage, LocalStorage, RedisStorage, SQLStorage
router = APIRouter()
@router.get("/verify", dependencies=[Depends(verify_app_key)])
async def admin_verify():
"""验证后台访问密钥(app_key)"""
return {"status": "success"}
@router.get("/config", dependencies=[Depends(verify_app_key)])
async def get_config():
"""获取当前配置"""
# 暴露原始配置字典
return config._config
@router.post("/config", dependencies=[Depends(verify_app_key)])
async def update_config(data: dict):
"""更新配置"""
try:
await config.update(data)
return {"status": "success", "message": "配置已更新"}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.get("/storage", dependencies=[Depends(verify_app_key)])
async def get_storage():
"""获取当前存储模式"""
storage_type = os.getenv("SERVER_STORAGE_TYPE", "").lower()
if not storage_type:
storage = get_storage()
if isinstance(storage, LocalStorage):
storage_type = "local"
elif isinstance(storage, RedisStorage):
storage_type = "redis"
elif isinstance(storage, SQLStorage):
storage_type = {
"mysql": "mysql",
"mariadb": "mysql",
"postgres": "pgsql",
"postgresql": "pgsql",
"pgsql": "pgsql",
}.get(storage.dialect, storage.dialect)
return {"type": storage_type or "local"}
|