mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-05-10 17:43:35 +08:00
- Updated import statements across multiple modules to use relative imports for better encapsulation. - Consolidated and organized the `__init__.py` files in various domain packages to expose necessary classes and functions. - Improved code readability and maintainability by grouping related imports and removing unused ones. - Ensured consistent import patterns across the domain, enhancing the overall structure of the codebase.
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends, Form, Request
|
|
|
|
from api.response import success
|
|
from domain.audit import AuditAction, audit
|
|
from domain.auth import User, get_current_active_user
|
|
from .service import ConfigService
|
|
from .types import ConfigItem
|
|
|
|
router = APIRouter(prefix="/api/config", tags=["config"])
|
|
|
|
|
|
@router.get("/")
|
|
@audit(action=AuditAction.READ, description="获取配置")
|
|
async def get_config(
|
|
request: Request,
|
|
current_user: Annotated[User, Depends(get_current_active_user)],
|
|
key: str,
|
|
):
|
|
value = await ConfigService.get(key)
|
|
return success(ConfigItem(key=key, value=value).model_dump())
|
|
|
|
|
|
@router.post("/")
|
|
@audit(action=AuditAction.UPDATE, description="设置配置", body_fields=["key", "value"])
|
|
async def set_config(
|
|
request: Request,
|
|
current_user: Annotated[User, Depends(get_current_active_user)],
|
|
key: str = Form(...),
|
|
value: str = Form(""),
|
|
):
|
|
await ConfigService.set(key, value)
|
|
return success(ConfigItem(key=key, value=value).model_dump())
|
|
|
|
|
|
@router.get("/all")
|
|
@audit(action=AuditAction.READ, description="获取全部配置")
|
|
async def get_all_config(
|
|
request: Request,
|
|
current_user: Annotated[User, Depends(get_current_active_user)],
|
|
):
|
|
configs = await ConfigService.get_all()
|
|
return success(configs)
|
|
|
|
|
|
@router.get("/status")
|
|
@audit(action=AuditAction.READ, description="获取系统状态")
|
|
async def get_system_status(request: Request):
|
|
status_data = await ConfigService.get_system_status()
|
|
return success(status_data.model_dump())
|
|
|
|
|
|
@router.get("/latest-version")
|
|
@audit(action=AuditAction.READ, description="获取最新版本")
|
|
async def get_latest_version(request: Request):
|
|
info = await ConfigService.get_latest_version()
|
|
return success(info.model_dump())
|