-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/binaryify/netease-cloud-music-api/7wntbqp81 |
去掉了 http://localhost:port/ public 里面的网页 lang 都改成 zh 了
既然改成了map为啥不这样处理: |
现在应该好看点了 |
因为函数重构了 直接用 function 了 没有注意到其它函数是变量形式的
else if (ua === 'pc') index = Math.floor(Math.random() * 5) + 8 | ||
else return ua | ||
return userAgentList[index] | ||
const chooseUserAgent = (ua = false) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么使用布尔值作为缺省值呢?传入参数的类型是 String,那么缺省略值应该为 undefined 或者 '' 更为合理
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我写了个 测试 你可以看看
https://gist.github.com/makeding/e5a08b12e0aaba3d59cc9db1a6c19b69
js 也不是强类型语言啦
我觉得为 false 这样完全可以 (代码更简单点)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
主要是逻辑上的优先可以修改下(稍晚给个例子)。还有就是 options.ua
在目前的实现不是一个可以自由传入的参数。具体的传入参数可以参考 modules 目录
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const userAgentList = {
mobile: [
// iOS 13.5.1 14.0 beta with safari
'Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1',
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.',
// iOS with qq micromsg
'Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML like Gecko) Mobile/14A456 QQ/6.5.7.408 V1_IPH_SQ_6.5.7_1_APP_A Pixel/750 Core/UIWebView NetType/4G Mem/103',
'Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.15(0x17000f27) NetType/WIFI Language/zh',
// Android -> Huawei Xiaomi
'Mozilla/5.0 (Linux; Android 9; PCT-AL10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.64 HuaweiBrowser/10.0.3.311 Mobile Safari/537.36',
'Mozilla/5.0 (Linux; U; Android 9; zh-cn; Redmi Note 8 Build/PKQ1.190616.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.141 Mobile Safari/537.36 XiaoMi/MiuiBrowser/12.5.22',
// Android + qq micromsg
'Mozilla/5.0 (Linux; Android 10; YAL-AL00 Build/HUAWEIYAL-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.62 XWEB/2581 MMWEBSDK/200801 Mobile Safari/537.36 MMWEBID/3027 MicroMessenger/7.0.18.1740(0x27001235) Process/toolsmp WeChat/arm64 NetType/WIFI Language/zh_CN ABI/arm64',
'Mozilla/5.0 (Linux; U; Android 8.1.0; zh-cn; BKK-AL10 Build/HONORBKK-AL10) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/10.6 Mobile Safari/537.36',
],
pc: [
// macOS 10.15.6 Firefox / Chrome / Safari
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:80.0) Gecko/20100101 Firefox/80.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.30 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15',
// Windows 10 Firefox / Chrome / Edge
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.30 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/13.10586'
// Linux 就算了
]
} // 把 UA 单独抽离出来,提高解析性能
/**
* 取得 User Agent
* @param {string} [ua] // 实际上这个函数也不该做这个工作,既然上游已经指定了 UA 为什么还要传入这个函数呢
* // 理想的注释 @params {'pc' | 'mobile' } [ua]
* @returns {string}
*/
const chooseUserAgent = (ua) => {
// 假设 UA 是自定义值的话,实际上目前的实现不能自定义值
if (ua && !['pc', 'mobile'].includes(ua)) {
return ua
}
const userAgentList = userAgentList[ua] || (userAgentList.mobile).concat(userAgentList.pc)
return realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)]
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options.ua 我之前也扫了一遍(写示例 gist 的时候搜索的)
确实是只有几个 modules (login_cellphone.js/login_refresh.js/login.js/logout.js/related_playlist.js/search_hot.js)
而且调用 api 的时候不能传入自定义 ua 进去,也就是你这边提到的不是一个可以自由传入的参数
// 也就是要完善 ua 相关功能还要大改
要先确定个方向,比如要不要 api 考虑做传入自定义 ua 的功能之类的
然后随机 ua 是不是要考虑做个持久点的,比如一段时间用这个,一段时间再随机别的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个可以开个 issue 讨论。我的建议是现在保留兼容即可。也就是直接:
const chooseUserAgent = (ua) => {
const userAgentList = userAgentList[ua] || (userAgentList.mobile).concat(userAgentList.pc)
return realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)]
}
在 Deepin 下测试 1.2.0(0408) UA 是 Chrome 60 ,并不会跟着系统版本更新。
我先合了吧,测试下 github action, 有优化再另外提PR吧 |
RT 本来只更新了下UA的 后面发现随机UA的函数问题很大,所以就优化了下
相关代码在 /util/request.js