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

Commit

Permalink
修复 Nodejs 下 cookie 使用格式问题 #812
Browse files Browse the repository at this point in the history
  • Loading branch information
Binaryify committed Jun 7, 2020
1 parent 1a36224 commit 20cba0a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
5 changes: 5 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -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 : {}
Expand Down
7 changes: 6 additions & 1 deletion module_example/test.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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)
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": "3.32.2",
"version": "3.32.3",
"description": "网易云音乐 NodeJS 版 API",
"scripts": {
"start": "node app.js",
Expand Down
9 changes: 9 additions & 0 deletions util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 20cba0a

Please sign in to comment.