Skip to content

Commit 3e5c052

Browse files
committed
fix: 支持headers不携带cookie信息 #1744 #1748
1 parent 0ff32ac commit 3e5c052

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

CHANGELOG.MD

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# 更新日志
2+
3+
### 4.8.11 | 2023.05.29
4+
- 支持headers不携带cookie信息
5+
26
### 4.8.10 | 2023.04.07
37
- 补充私信和通知接口
48

docs/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,8 @@ $ sudo docker run -d -p 3000:3000 netease-music-api
481481

482482
!> 分页接口返回字段里有`more`,more 为 true 则为有下一页
483483

484+
!> 如果不需要接口headers携带cookies信息,可以加上noCookie参数,如`?noCookie=true`
485+
484486
### 登录
485487

486488
说明 : 登录有三个接口,建议使用`encodeURIComponent`对密码编码或者使用`POST`请求,避免某些特殊字符无法解析,如`#`(`#`在 url 中会被识别为 hash,而不是 query)

package.json

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

public/qrlogin.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<script>
1616
async function checkStatus(key) {
1717
const res = await axios({
18-
url: `/login/qr/check?key=${key}&timestamp=${Date.now()}`,
18+
url: `/login/qr/check?key=${key}&timestamp=${Date.now()}&noCookie=true`,
1919
})
2020
return res.data
2121
}

server.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,19 @@ async function consturctServer(moduleDefs) {
239239
console.log('[OK]', decode(req.originalUrl))
240240

241241
const cookies = moduleResponse.cookie
242-
if (Array.isArray(cookies) && cookies.length > 0) {
243-
if (req.protocol === 'https') {
244-
// Try to fix CORS SameSite Problem
245-
res.append(
246-
'Set-Cookie',
247-
cookies.map((cookie) => {
248-
return cookie + '; SameSite=None; Secure'
249-
}),
250-
)
251-
} else {
252-
res.append('Set-Cookie', cookies)
242+
if (!query.noCookie) {
243+
if (Array.isArray(cookies) && cookies.length > 0) {
244+
if (req.protocol === 'https') {
245+
// Try to fix CORS SameSite Problem
246+
res.append(
247+
'Set-Cookie',
248+
cookies.map((cookie) => {
249+
return cookie + '; SameSite=None; Secure'
250+
}),
251+
)
252+
} else {
253+
res.append('Set-Cookie', cookies)
254+
}
253255
}
254256
}
255257
res.status(moduleResponse.status).send(moduleResponse.body)
@@ -268,7 +270,10 @@ async function consturctServer(moduleDefs) {
268270
}
269271
if (moduleResponse.body.code == '301')
270272
moduleResponse.body.msg = '需要登录'
271-
res.append('Set-Cookie', moduleResponse.cookie)
273+
if (!query.noCookie) {
274+
res.append('Set-Cookie', moduleResponse.cookie)
275+
}
276+
272277
res.status(moduleResponse.status).send(moduleResponse.body)
273278
}
274279
})

0 commit comments

Comments
 (0)