MCPcopy Create free account
hub / github.com/TheSmallHanCat/flow2api / add_token

Function add_token

src/api/admin.py:861–909  ·  view source on GitHub ↗

Add a new token

(
    request: AddTokenRequest,
    token: str = Depends(verify_admin_token)
)

Source from the content-addressed store, hash-verified

859
860@router.post("/api/tokens")
861async def add_token(
862 request: AddTokenRequest,
863 token: str = Depends(verify_admin_token)
864):
865 """Add a new token"""
866 try:
867 new_token = await token_manager.add_token(
868 st=request.st,
869 project_id=request.project_id, # 🆕 支持用户指定project_id
870 project_name=request.project_name,
871 remark=request.remark,
872 captcha_proxy_url=request.captcha_proxy_url.strip() if request.captcha_proxy_url is not None else None,
873 extension_route_key=request.extension_route_key.strip() if request.extension_route_key is not None else None,
874 image_enabled=request.image_enabled,
875 video_enabled=request.video_enabled,
876 image_concurrency=request.image_concurrency,
877 video_concurrency=request.video_concurrency,
878 protocol_mode=request.protocol_mode,
879 google_cookies=request.google_cookies,
880 login_account=request.login_account,
881 login_password=request.login_password,
882 proxy_url=request.proxy_url,
883 auto_refresh_enabled=request.auto_refresh_enabled,
884 refresh_interval_minutes=request.refresh_interval_minutes
885 )
886
887 # 热更新并发限制,避免必须重启服务
888 if concurrency_manager:
889 await concurrency_manager.reset_token(
890 new_token.id,
891 image_concurrency=new_token.image_concurrency,
892 video_concurrency=new_token.video_concurrency
893 )
894
895 return {
896 "success": True,
897 "message": "Token添加成功",
898 "token": {
899 "id": new_token.id,
900 "email": new_token.email,
901 "credits": new_token.credits,
902 "project_id": new_token.current_project_id,
903 "project_name": new_token.current_project_name
904 }
905 }
906 except ValueError as e:
907 raise HTTPException(status_code=400, detail=str(e))
908 except Exception as e:
909 raise HTTPException(status_code=500, detail=f"添加Token失败: {str(e)}")
910
911
912@router.put("/api/tokens/{token_id}")

Callers

nothing calls this directly

Calls 2

reset_tokenMethod · 0.80
add_tokenMethod · 0.45

Tested by

no test coverage detected