Skip to content

Commit e20e3c1

Browse files
committed
又优化了下 UA 逻辑 现在两行就 ok 了
Binaryify/NeteaseCloudMusicApi#922
1 parent 650afad commit e20e3c1

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

util/request.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,8 @@ function chooseUserAgent(ua = false) {
3535
// Linux 就算了
3636
]
3737
}
38-
let realUserAgentList = []
39-
if (!ua)
40-
realUserAgentList = (userAgentList.mobile).concat(userAgentList.pc) // concat 把两个 array 合并
41-
else if (ua == 'mobile')
42-
realUserAgentList = userAgentList.mobile
43-
else if (ua == 'pc')
44-
realUserAgentList = userAgentList.pc
45-
else
46-
return ua // 最后返回自定义的 ua
47-
return realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)]
38+
let realUserAgentList = userAgentList[ua] || (userAgentList.mobile).concat(userAgentList.pc)
39+
return (['mobile', 'pc', false].indexOf(ua) > -1) ? realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)] : ua
4840
}
4941
const createRequest = (method, url, data, options) => {
5042
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)