* 刷新单个账户的令牌 * @param {Object} account - 账户对象 {email, password, token, expires} * @returns {Promise } 更新后的账户对象或null
(account)
| 128 | |
| 129 | /** |
| 130 | * 刷新单个账户的令牌 |
| 131 | * @param {Object} account - 账户对象 {email, password, token, expires} |
| 132 | * @returns {Promise<Object|null>} 更新后的账户对象或null |
| 133 | */ |
| 134 | async refreshToken(account) { |
| 135 | try { |
| 136 | const newToken = await this.login(account.email, account.password, account) |
| 137 | if (!newToken) { |
| 138 | return null |
| 139 | } |
| 140 | |
| 141 | const decoded = this.validateToken(newToken) |
| 142 | if (!decoded) { |
| 143 | logger.error(`刷新后的令牌无效: ${account.email}`, 'TOKEN') |
| 144 | return null |
| 145 | } |
| 146 | |
| 147 | const updatedAccount = { |
| 148 | ...account, |
| 149 | token: newToken, |
| 150 | expires: decoded.exp |
| 151 | } |
| 152 | |
| 153 | const remainingHours = this.getTokenRemainingHours(newToken) |
| 154 | logger.success(`令牌刷新成功: ${account.email} (有效期: ${remainingHours}小时)`, 'TOKEN') |
| 155 | |
| 156 | return updatedAccount |
| 157 | } catch (error) { |
| 158 | logger.error(`刷新令牌失败 (${account.email})`, 'TOKEN', '', error) |
| 159 | return null |
| 160 | } |
no test coverage detected