diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 30b14f5a913..60e265d1334 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,4 +1,7 @@ # 更新日志 +### 3.32.3 | 2020.06.07 +- 修复 Nodejs 下 cookie 使用格式问题 [#812](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/812) + ### 3.32.2 | 2020.06.05 - 新增独家放送列表接口 [#808](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/808) diff --git a/main.js b/main.js index afd85bec7b1..db2965df1ef 100644 --- a/main.js +++ b/main.js @@ -1,12 +1,17 @@ const fs = require('fs') const path = require('path') const request = require('./util/request') +const { cookieToJson } = require('./util/index') + let obj = {} fs.readdirSync(path.join(__dirname, 'module')).reverse().forEach(file => { if(!file.endsWith('.js')) return let fileModule = require(path.join(__dirname, 'module', file)) obj[file.split('.').shift()] = function (data) { + if(typeof data.cookie === 'string'){ + data.cookie = cookieToJson(data.cookie) + } return fileModule({ ...data, cookie: data.cookie ? data.cookie : {} diff --git a/module_example/test.js b/module_example/test.js index c126a6d8e7f..93a4db5f218 100644 --- a/module_example/test.js +++ b/module_example/test.js @@ -1,4 +1,4 @@ -const { login_cellphone, user_cloud, album_sublist } = require('../main') +const { login_cellphone, user_cloud, album_sublist, song_url } = require('../main') async function test() { try { const result = await login_cellphone({ @@ -14,6 +14,11 @@ async function test() { cookie: result.body.cookie }) console.log(result3.body) + const result4 = await song_url({ + cookie: result.body.cookie, + id: 33894312 + }) + console.log(result4.body) } catch (error) { console.log(error) diff --git a/package.json b/package.json index 5aef164128e..2777ef2e37a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "NeteaseCloudMusicApi", - "version": "3.32.2", + "version": "3.32.3", "description": "网易云音乐 NodeJS 版 API", "scripts": { "start": "node app.js", diff --git a/util/index.js b/util/index.js index b5268019e40..e1aa4b871d3 100644 --- a/util/index.js +++ b/util/index.js @@ -2,5 +2,14 @@ module.exports = { toBoolean(val) { if (val === '') return val return val === 'true' || val == '1' + }, + cookieToJson(cookie) { + let cookieArr = cookie.split(';'); + let obj = {} + cookieArr.forEach((i) => { + let arr = i.split('='); + obj[arr[0]] = arr[1]; + }); + return obj } }