又优化了下 UA 逻辑 现在两行就 ok 了

https://github.com/Binaryify/NeteaseCloudMusicApi/pull/922
This commit is contained in:
huggy 2020-09-11 10:24:52 +08:00
parent c05c83db14
commit e933997d26

View File

@ -35,16 +35,8 @@ function chooseUserAgent(ua = false) {
// Linux 就算了
]
}
let realUserAgentList = []
if (!ua)
realUserAgentList = (userAgentList.mobile).concat(userAgentList.pc) // concat 把两个 array 合并
else if (ua == 'mobile')
realUserAgentList = userAgentList.mobile
else if (ua == 'pc')
realUserAgentList = userAgentList.pc
else
return ua // 最后返回自定义的 ua
return realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)]
let realUserAgentList = userAgentList[ua] || (userAgentList.mobile).concat(userAgentList.pc)
return (['mobile', 'pc', false].indexOf(ua) > -1) ? realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)] : ua
}
const createRequest = (method, url, data, options) => {
return new Promise((resolve, reject) => {