refactor: 凭证下沉账号层——平台不再持有API凭证;账号支持登录凭证+API配置,SDK测试/同步改为账号维度,同步产出自动挂账号;含存量数据自动迁移

This commit is contained in:
gouki
2026-08-09 16:50:45 +00:00
parent cf18cadb6b
commit dc2134cf5a
9 changed files with 355 additions and 103 deletions
+20 -1
View File
@@ -2,6 +2,7 @@
统一入口 /api/accounts,写操作(POST/PUT/DELETE)受 API Key 保护。
资产的 Asset.account 按名称引用账号;重命名账号时服务层会同步更新引用资产。
凭证(登录密码/API 配置)存在账号上;账号维度的 SDK 测试/同步见 test/sync 端点。
"""
from typing import List
@@ -12,7 +13,7 @@ from sqlmodel import Session
from app.core.security import require_api_key
from app.database import get_session
from app.schemas.account import AccountCreate, AccountRead, AccountUpdate
from app.services import account_service
from app.services import account_service, sync_service
router = APIRouter(prefix="/api/accounts", tags=["accounts"])
@@ -52,3 +53,21 @@ def update_account(
)
def delete_account(account_id: int, session: Session = Depends(get_session)) -> dict:
return account_service.delete_account(session, account_id)
@router.post(
"/{account_id}/test",
summary="测试账号凭证有效性(按账号所属平台的 SDK)",
dependencies=[Depends(require_api_key)],
)
def test_account(account_id: int, session: Session = Depends(get_session)) -> dict:
return sync_service.test_account(session, account_id)
@router.post(
"/{account_id}/sync",
summary="同步账号资产到本地库(产出自动挂到该账号名下)",
dependencies=[Depends(require_api_key)],
)
def sync_account(account_id: int, session: Session = Depends(get_session)) -> dict:
return sync_service.sync_account(session, account_id)