feat: normalize adapter types and improve validation in adapters

This commit is contained in:
shiyu
2025-11-20 12:43:41 +08:00
parent 219f3e81b8
commit 3278896d4b
12 changed files with 83 additions and 23 deletions

View File

@@ -5,7 +5,7 @@ from typing import Annotated
from models import StorageAdapter
from schemas import AdapterCreate, AdapterOut
from services.auth import get_current_active_user, User
from services.adapters.registry import runtime_registry, get_config_schemas
from services.adapters.registry import runtime_registry, get_config_schemas, normalize_adapter_type
from api.response import success
from services.logging import LogService
@@ -14,6 +14,9 @@ router = APIRouter(prefix="/api/adapters", tags=["adapters"])
def validate_and_normalize_config(adapter_type: str, cfg):
schemas = get_config_schemas()
adapter_type = normalize_adapter_type(adapter_type)
if not adapter_type:
raise HTTPException(400, detail="不支持的适配器类型")
if not isinstance(cfg, dict):
raise HTTPException(400, detail="config 必须是对象")
schema = schemas.get(adapter_type)
@@ -77,17 +80,10 @@ async def list_adapters(
async def available_adapter_types(
current_user: Annotated[User, Depends(get_current_active_user)]
):
name_map = {
"local": "本地文件系统",
"webdav": "WebDAV",
"GoogleDrive": "Google Drive",
"OneDrive": "OneDrive",
}
data = []
for t, fields in get_config_schemas().items():
data.append({
"type": t,
"name": name_map.get(t, t),
"config_schema": fields,
})
return success(data)