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

Function refresh_at

src/api/admin.py:1026–1074  ·  view source on GitHub ↗

手动刷新Token的AT (使用ST转换) 🆕 如果 AT 刷新失败且处于 personal 模式,会自动尝试通过浏览器刷新 ST

(
    token_id: int,
    token: str = Depends(verify_admin_token)
)

Source from the content-addressed store, hash-verified

1024
1025@router.post("/api/tokens/{token_id}/refresh-at")
1026async def refresh_at(
1027 token_id: int,
1028 token: str = Depends(verify_admin_token)
1029):
1030 """手动刷新Token的AT (使用ST转换) 🆕
1031
1032 如果 AT 刷新失败且处于 personal 模式,会自动尝试通过浏览器刷新 ST
1033 """
1034 from ..core.logger import debug_logger
1035 from ..core.config import config
1036
1037 debug_logger.log_info(f"[API] 手动刷新 AT 请求: token_id={token_id}, captcha_method={config.captcha_method}")
1038
1039 try:
1040 # 调用token_manager的内部刷新方法(包含 ST 自动刷新逻辑)
1041 success = await token_manager._refresh_at(token_id)
1042
1043 if success:
1044 # 获取更新后的token信息
1045 updated_token = await token_manager.get_token(token_id)
1046
1047 message = "AT刷新成功"
1048 if config.captcha_method == "personal":
1049 message += "(支持ST自动刷新)"
1050
1051 debug_logger.log_info(f"[API] AT 刷新成功: token_id={token_id}")
1052
1053 return {
1054 "success": True,
1055 "message": message,
1056 "token": {
1057 "id": updated_token.id,
1058 "email": updated_token.email,
1059 "at_expires": updated_token.at_expires.isoformat() if updated_token.at_expires else None
1060 }
1061 }
1062 else:
1063 debug_logger.log_error(f"[API] AT 刷新失败: token_id={token_id}")
1064
1065 error_detail = "AT刷新失败"
1066 if config.captcha_method != "personal":
1067 error_detail += f"(当前打码模式: {config.captcha_method},ST自动刷新仅在 personal 模式下可用)"
1068
1069 raise HTTPException(status_code=500, detail=error_detail)
1070 except HTTPException:
1071 raise
1072 except Exception as e:
1073 debug_logger.log_error(f"[API] 刷新AT异常: {str(e)}")
1074 raise HTTPException(status_code=500, detail=f"刷新AT失败: {str(e)}")
1075
1076
1077@router.post("/api/tokens/st2at")

Callers

nothing calls this directly

Calls 4

log_infoMethod · 0.80
_refresh_atMethod · 0.80
log_errorMethod · 0.80
get_tokenMethod · 0.45

Tested by

no test coverage detected