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

Commit 20cba0a

Browse files
committed
修复 Nodejs 下 cookie 使用格式问题 #812
1 parent 1a36224 commit 20cba0a

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

CHANGELOG.MD

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# 更新日志
2+
### 3.32.3 | 2020.06.07
3+
- 修复 Nodejs 下 cookie 使用格式问题 [#812](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/812)
4+
25
### 3.32.2 | 2020.06.05
36
- 新增独家放送列表接口 [#808](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/808)
47

main.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
const fs = require('fs')
22
const path = require('path')
33
const request = require('./util/request')
4+
const { cookieToJson } = require('./util/index')
45

6+
57
let obj = {}
68
fs.readdirSync(path.join(__dirname, 'module')).reverse().forEach(file => {
79
if(!file.endsWith('.js')) return
810
let fileModule = require(path.join(__dirname, 'module', file))
911
obj[file.split('.').shift()] = function (data) {
12+
if(typeof data.cookie === 'string'){
13+
data.cookie = cookieToJson(data.cookie)
14+
}
1015
return fileModule({
1116
...data,
1217
cookie: data.cookie ? data.cookie : {}

module_example/test.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { login_cellphone, user_cloud, album_sublist } = require('../main')
1+
const { login_cellphone, user_cloud, album_sublist, song_url } = require('../main')
22
async function test() {
33
try {
44
const result = await login_cellphone({
@@ -14,6 +14,11 @@ async function test() {
1414
cookie: result.body.cookie
1515
})
1616
console.log(result3.body)
17+
const result4 = await song_url({
18+
cookie: result.body.cookie,
19+
id: 33894312
20+
})
21+
console.log(result4.body)
1722

1823
} catch (error) {
1924
console.log(error)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "NeteaseCloudMusicApi",
3-
"version": "3.32.2",
3+
"version": "3.32.3",
44
"description": "网易云音乐 NodeJS 版 API",
55
"scripts": {
66
"start": "node app.js",

util/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,14 @@ module.exports = {
22
toBoolean(val) {
33
if (val === '') return val
44
return val === 'true' || val == '1'
5+
},
6+
cookieToJson(cookie) {
7+
let cookieArr = cookie.split(';');
8+
let obj = {}
9+
cookieArr.forEach((i) => {
10+
let arr = i.split('=');
11+
obj[arr[0]] = arr[1];
12+
});
13+
return obj
514
}
615
}

0 commit comments

Comments
 (0)