提交 1eb178d0 编写于 作者: B binaryify

修复 eapi 接口无法正确解密response的问题 #1138

上级 d289f633
# 更新日志 # 更新日志
### 4.0.6 | 2021.2.20
- 修复 eapi 接口无法正确解密response的问题 [#1138](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1138)
### 4.0.5 | 2021.2.19 ### 4.0.5 | 2021.2.19
- 修复红心接口默认不红心的问题 [#1126](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1126) - 修复红心接口默认不红心的问题 [#1126](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1126)
......
{ {
"name": "NeteaseCloudMusicApi", "name": "NeteaseCloudMusicApi",
"version": "4.0.5", "version": "4.0.6",
"description": "网易云音乐 NodeJS 版 API", "description": "网易云音乐 NodeJS 版 API",
"scripts": { "scripts": {
"start": "node app.js", "start": "node app.js",
......
...@@ -111,7 +111,7 @@ const createRequest = (method, url, data, options) => { ...@@ -111,7 +111,7 @@ const createRequest = (method, url, data, options) => {
} }
const answer = { status: 500, body: {}, cookie: [] } const answer = { status: 500, body: {}, cookie: [] }
const settings = { let settings = {
method: method, method: method,
url: url, url: url,
headers: headers, headers: headers,
...@@ -143,7 +143,12 @@ const createRequest = (method, url, data, options) => { ...@@ -143,7 +143,12 @@ const createRequest = (method, url, data, options) => {
} }
} }
} }
if (options.crypto === 'eapi') {
settings = {
...settings,
responseType: 'arraybuffer',
}
}
axios(settings) axios(settings)
.then((res) => { .then((res) => {
const body = res.data const body = res.data
...@@ -151,7 +156,12 @@ const createRequest = (method, url, data, options) => { ...@@ -151,7 +156,12 @@ const createRequest = (method, url, data, options) => {
x.replace(/\s*Domain=[^(;|$)]+;*/, ''), x.replace(/\s*Domain=[^(;|$)]+;*/, ''),
) )
try { try {
answer.body = body if (options.crypto === 'eapi') {
answer.body = JSON.parse(encrypt.decrypt(body).toString())
} else {
answer.body = body
}
answer.status = answer.body.code || res.status answer.status = answer.body.code || res.status
if ( if (
[201, 302, 400, 502, 800, 801, 802, 803].indexOf(answer.body.code) > [201, 302, 400, 502, 800, 801, 802, 803].indexOf(answer.body.code) >
...@@ -161,6 +171,7 @@ const createRequest = (method, url, data, options) => { ...@@ -161,6 +171,7 @@ const createRequest = (method, url, data, options) => {
answer.status = 200 answer.status = 200
} }
} catch (e) { } catch (e) {
// console.log(e)
answer.body = body answer.body = body
answer.status = res.status answer.status = res.status
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册