mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-10-24 00:21:23 +08:00
fix: 修复空 cookie 对象处理
This commit is contained in:
@@ -103,6 +103,15 @@ module.exports = {
|
||||
return obj
|
||||
},
|
||||
|
||||
hasCookie(cookie) {
|
||||
if (typeof cookie === 'string') return cookie.length > 0
|
||||
return (
|
||||
cookie !== null &&
|
||||
typeof cookie === 'object' &&
|
||||
Object.keys(cookie).length > 0
|
||||
)
|
||||
},
|
||||
|
||||
cookieObjToString(cookie) {
|
||||
// 优化:使用预绑定的keys函数和for循环
|
||||
const cookieKeys = keys(cookie)
|
||||
@@ -226,6 +235,8 @@ const cookieToJsonOptimized = (function() {
|
||||
function getCookieValue(cookieStr, name) {
|
||||
if (!cookieStr) return ''
|
||||
|
||||
if (typeof cookieStr === 'object') return cookieStr[name] || ''
|
||||
|
||||
const cookies = '; ' + cookieStr
|
||||
const parts = cookies.split('; ' + name + '=')
|
||||
if (parts.length === 2) return parts.pop().split(';').shift()
|
||||
|
||||
+5
-1
@@ -1,7 +1,11 @@
|
||||
const { hasCookie } = require('./index')
|
||||
|
||||
const createOption = (query, crypto = '', checkToken = false) => {
|
||||
return {
|
||||
crypto: query.crypto || crypto || '',
|
||||
cookie: query.cookie || process.env.NETEASE_COOKIE,
|
||||
cookie: hasCookie(query.cookie)
|
||||
? query.cookie
|
||||
: process.env.NETEASE_COOKIE,
|
||||
ua: query.ua || '',
|
||||
proxy: query.proxy,
|
||||
realIP: query.realIP,
|
||||
|
||||
Reference in New Issue
Block a user