fix: 支持headers不携带cookie信息 #1744 #1748

This commit is contained in:
binaryify 2023-05-29 16:30:36 +08:00
parent 0ff32acdc1
commit 3e5c052f98
5 changed files with 25 additions and 14 deletions

View File

@ -1,4 +1,8 @@
# 更新日志
### 4.8.11 | 2023.05.29
- 支持headers不携带cookie信息
### 4.8.10 | 2023.04.07
- 补充私信和通知接口

View File

@ -481,6 +481,8 @@ $ sudo docker run -d -p 3000:3000 netease-music-api
!> 分页接口返回字段里有`more`,more 为 true 则为有下一页
!> 如果不需要接口headers携带cookies信息,可以加上noCookie参数,如`?noCookie=true`
### 登录
说明 : 登录有三个接口,建议使用`encodeURIComponent`对密码编码或者使用`POST`请求,避免某些特殊字符无法解析,如`#`(`#`在 url 中会被识别为 hash,而不是 query)

View File

@ -1,6 +1,6 @@
{
"name": "NeteaseCloudMusicApi",
"version": "4.8.10",
"version": "4.8.11",
"description": "网易云音乐 NodeJS 版 API",
"scripts": {
"start": "node app.js",

View File

@ -15,7 +15,7 @@
<script>
async function checkStatus(key) {
const res = await axios({
url: `/login/qr/check?key=${key}&timestamp=${Date.now()}`,
url: `/login/qr/check?key=${key}&timestamp=${Date.now()}&noCookie=true`,
})
return res.data
}

View File

@ -239,17 +239,19 @@ async function consturctServer(moduleDefs) {
console.log('[OK]', decode(req.originalUrl))
const cookies = moduleResponse.cookie
if (Array.isArray(cookies) && cookies.length > 0) {
if (req.protocol === 'https') {
// Try to fix CORS SameSite Problem
res.append(
'Set-Cookie',
cookies.map((cookie) => {
return cookie + '; SameSite=None; Secure'
}),
)
} else {
res.append('Set-Cookie', cookies)
if (!query.noCookie) {
if (Array.isArray(cookies) && cookies.length > 0) {
if (req.protocol === 'https') {
// Try to fix CORS SameSite Problem
res.append(
'Set-Cookie',
cookies.map((cookie) => {
return cookie + '; SameSite=None; Secure'
}),
)
} else {
res.append('Set-Cookie', cookies)
}
}
}
res.status(moduleResponse.status).send(moduleResponse.body)
@ -268,7 +270,10 @@ async function consturctServer(moduleDefs) {
}
if (moduleResponse.body.code == '301')
moduleResponse.body.msg = '需要登录'
res.append('Set-Cookie', moduleResponse.cookie)
if (!query.noCookie) {
res.append('Set-Cookie', moduleResponse.cookie)
}
res.status(moduleResponse.status).send(moduleResponse.body)
}
})