feat: sync upstream keys and reorder priorities
This commit is contained in:
@@ -23,6 +23,9 @@ from app.schemas.website import (
|
||||
ImportGroupItem,
|
||||
ImportGroupsRequest,
|
||||
ImportGroupsResponse,
|
||||
ReorderPriorityItem,
|
||||
ReorderPriorityRequest,
|
||||
ReorderPriorityResponse,
|
||||
SyncImportStatusRequest,
|
||||
TestResult,
|
||||
WebsiteCreate,
|
||||
@@ -34,7 +37,13 @@ from app.schemas.website import (
|
||||
)
|
||||
|
||||
from app.services.website_client import Sub2ApiWebsiteClient
|
||||
from app.services.website_sync import binding_sources, sync_binding, build_rate_priority_map, reconcile_upstream_keys_full
|
||||
from app.services.website_sync import (
|
||||
binding_sources,
|
||||
sync_binding,
|
||||
build_rate_priority_map,
|
||||
reconcile_upstream_keys_full,
|
||||
sync_account_priorities_for_upstream,
|
||||
)
|
||||
from app.utils.auth import get_current_user
|
||||
|
||||
router = APIRouter(tags=["websites"])
|
||||
@@ -463,6 +472,44 @@ def sync_imported_upstream_keys(
|
||||
)
|
||||
|
||||
|
||||
@router.post("/api/websites/{wid}/accounts/reorder-priority", response_model=ReorderPriorityResponse)
|
||||
def reorder_account_priorities(
|
||||
wid: int,
|
||||
body: ReorderPriorityRequest,
|
||||
db: Session = Depends(get_db),
|
||||
_=Depends(get_current_user),
|
||||
):
|
||||
website = db.query(Website).filter(Website.id == wid).first()
|
||||
if not website:
|
||||
raise HTTPException(404, "website not found")
|
||||
if website.site_type != "sub2api":
|
||||
raise HTTPException(400, "目前只支持 sub2api")
|
||||
|
||||
upstream = db.query(Upstream).filter(Upstream.id == body.upstream_id).first()
|
||||
if not upstream:
|
||||
raise HTTPException(404, "upstream not found")
|
||||
|
||||
results = sync_account_priorities_for_upstream(db, body.upstream_id, website_id=wid)
|
||||
failed_count = sum(1 for item in results if item.get("status") == "failed")
|
||||
success_count = sum(1 for item in results if item.get("status") == "success")
|
||||
skipped_count = sum(1 for item in results if item.get("status") == "skipped")
|
||||
|
||||
parts = []
|
||||
if success_count:
|
||||
parts.append(f"更新 {success_count}")
|
||||
if failed_count:
|
||||
parts.append(f"失败 {failed_count}")
|
||||
if skipped_count:
|
||||
parts.append(f"跳过 {skipped_count}")
|
||||
message = "、".join(parts) + f" / 共 {len(results)} 个" if parts else "没有需要重排的账号"
|
||||
|
||||
return ReorderPriorityResponse(
|
||||
success=failed_count == 0,
|
||||
message=message,
|
||||
items=[ReorderPriorityItem(**item) for item in results],
|
||||
)
|
||||
|
||||
|
||||
@router.post("/api/websites/{wid}/accounts/import-upstream-keys", response_model=ImportAccountsResponse)
|
||||
def import_upstream_keys_as_accounts(
|
||||
wid: int,
|
||||
|
||||
Reference in New Issue
Block a user