mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-10-20 22:51:23 +08:00
feat: weapi支持checkToken
This commit is contained in:
@@ -34,5 +34,24 @@ module.exports = async (query) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 模块加载时自动获取一次 Token,确保 request.js 使用时不为空
|
||||
fetch()
|
||||
.then((token) => {
|
||||
_token = token
|
||||
})
|
||||
.catch(() => {
|
||||
// 静默失败,后续请求时会重试
|
||||
})
|
||||
|
||||
// 给 request.js 读取用
|
||||
module.exports.getToken = () => _token
|
||||
module.exports.getToken = () => {
|
||||
if (!_token) {
|
||||
// 如果 Token 为空,异步触发获取
|
||||
fetch()
|
||||
.then((token) => {
|
||||
_token = token
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
return _token
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user