Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
修复 eapi 接口无法正确解密response的问题 #1138
Browse files Browse the repository at this point in the history
  • Loading branch information
Binaryify committed Feb 21, 2021
1 parent d289f63 commit 1eb178d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# 更新日志
### 4.0.6 | 2021.2.20
- 修复 eapi 接口无法正确解密response的问题 [#1138](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1138)

### 4.0.5 | 2021.2.19
- 修复红心接口默认不红心的问题 [#1126](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1126)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "NeteaseCloudMusicApi",
"version": "4.0.5",
"version": "4.0.6",
"description": "网易云音乐 NodeJS 版 API",
"scripts": {
"start": "node app.js",
Expand Down
17 changes: 14 additions & 3 deletions util/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const createRequest = (method, url, data, options) => {
}

const answer = { status: 500, body: {}, cookie: [] }
const settings = {
let settings = {
method: method,
url: url,
headers: headers,
Expand Down Expand Up @@ -143,15 +143,25 @@ const createRequest = (method, url, data, options) => {
}
}
}

if (options.crypto === 'eapi') {
settings = {
...settings,
responseType: 'arraybuffer',
}
}
axios(settings)
.then((res) => {
const body = res.data
answer.cookie = (res.headers['set-cookie'] || []).map((x) =>
x.replace(/\s*Domain=[^(;|$)]+;*/, ''),
)
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
if (
[201, 302, 400, 502, 800, 801, 802, 803].indexOf(answer.body.code) >
Expand All @@ -161,6 +171,7 @@ const createRequest = (method, url, data, options) => {
answer.status = 200
}
} catch (e) {
// console.log(e)
answer.body = body
answer.status = res.status
}
Expand Down

1 comment on commit 1eb178d

@vercel
Copy link

@vercel vercel bot commented on 1eb178d Feb 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.