feat(newapi): enhance NEWAPI service management with channel configuration

- Added channel_type, channel_base_url, and channel_models fields to the NewapiService model.
- Updated CRUD operations to handle new fields for creating and updating NEWAPI services.
- Modified upload functions to accept channel configuration parameters.
- Enhanced front-end forms and tables to display and manage channel settings for NEWAPI services.
- Improved error handling and user feedback in the UI for service management.
This commit is contained in:
Jay Hsueh
2026-03-25 15:18:05 +08:00
parent ab353f0429
commit 9c6e0d6036
9 changed files with 121 additions and 15 deletions

View File

@@ -1014,7 +1014,14 @@ async def batch_upload_accounts_to_newapi(request: BatchUploadNewapiRequest):
request.status_filter, request.email_service_filter, request.search_filter
)
results = batch_upload_to_newapi(ids, api_url, api_key)
results = batch_upload_to_newapi(
ids,
api_url,
api_key,
channel_type=svc.channel_type,
channel_base_url=svc.channel_base_url,
channel_models=svc.channel_models,
)
return results
@@ -1035,7 +1042,14 @@ async def upload_account_to_newapi(account_id: int, request: Optional[UploadNewa
account = crud.get_account_by_id(db, account_id)
if not account:
raise HTTPException(status_code=404, detail="账号不存在")
success, message = upload_to_newapi(account, svc.api_url, svc.api_key)
success, message = upload_to_newapi(
account,
svc.api_url,
svc.api_key,
channel_type=svc.channel_type,
channel_base_url=svc.channel_base_url,
channel_models=svc.channel_models,
)
if success:
account.newapi_uploaded = True
account.newapi_uploaded_at = datetime.utcnow()

View File

@@ -797,7 +797,14 @@ def _run_sync_registration_task(task_uuid: str, email_service_type: str, proxy:
if not _svc:
continue
log_callback(f"[NEWAPI] 上传到服务: {_svc.name}")
_ok, _msg = upload_to_newapi(saved_account, _svc.api_url, _svc.api_key)
_ok, _msg = upload_to_newapi(
saved_account,
_svc.api_url,
_svc.api_key,
channel_type=_svc.channel_type,
channel_base_url=_svc.channel_base_url,
channel_models=_svc.channel_models,
)
if _ok:
saved_account.newapi_uploaded = True
saved_account.newapi_uploaded_at = datetime.utcnow()

View File

@@ -16,6 +16,9 @@ class NewapiServiceCreate(BaseModel):
name: str
api_url: str
api_key: str
channel_type: int = 57
channel_base_url: str = ""
channel_models: str = "gpt-5.4,gpt-5,gpt-5-codex,gpt-5-codex-mini,gpt-5.1,gpt-5.1-codex,gpt-5.1-codex-max,gpt-5.1-codex-mini,gpt-5.2,gpt-5.2-codex,gpt-5.3-codex,gpt-5-openai-compact,gpt-5-codex-openai-compact,gpt-5-codex-mini-openai-compact,gpt-5.1-openai-compact,gpt-5.1-codex-openai-compact,gpt-5.1-codex-max-openai-compact,gpt-5.1-codex-mini-openai-compact,gpt-5.2-openai-compact,gpt-5.2-codex-openai-compact,gpt-5.3-codex-openai-compact"
enabled: bool = True
priority: int = 0
@@ -24,6 +27,9 @@ class NewapiServiceUpdate(BaseModel):
name: Optional[str] = None
api_url: Optional[str] = None
api_key: Optional[str] = None
channel_type: Optional[int] = None
channel_base_url: Optional[str] = None
channel_models: Optional[str] = None
enabled: Optional[bool] = None
priority: Optional[int] = None
@@ -33,6 +39,9 @@ class NewapiServiceResponse(BaseModel):
name: str
api_url: str
has_key: bool
channel_type: int = 57
channel_base_url: str = ""
channel_models: str = ""
enabled: bool
priority: int
created_at: Optional[str] = None
@@ -48,6 +57,9 @@ def _to_response(svc) -> NewapiServiceResponse:
name=svc.name,
api_url=svc.api_url,
has_key=bool(svc.api_key),
channel_type=svc.channel_type if svc.channel_type is not None else 57,
channel_base_url=svc.channel_base_url or "",
channel_models=svc.channel_models or "",
enabled=svc.enabled,
priority=svc.priority,
created_at=svc.created_at.isoformat() if svc.created_at else None,
@@ -70,6 +82,9 @@ async def create_newapi_service(request: NewapiServiceCreate):
name=request.name,
api_url=request.api_url,
api_key=request.api_key,
channel_type=request.channel_type,
channel_base_url=request.channel_base_url,
channel_models=request.channel_models,
enabled=request.enabled,
priority=request.priority,
)
@@ -103,6 +118,12 @@ async def update_newapi_service(service_id: int, request: NewapiServiceUpdate):
update_data["enabled"] = request.enabled
if request.priority is not None:
update_data["priority"] = request.priority
if request.channel_type is not None:
update_data["channel_type"] = request.channel_type
if request.channel_base_url is not None:
update_data["channel_base_url"] = request.channel_base_url
if request.channel_models is not None:
update_data["channel_models"] = request.channel_models
svc = crud.update_newapi_service(db, service_id, **update_data)
return _to_response(svc)