mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-07-07 14:02:08 +08:00
allocate js cookie in middleware, update res cookie distribution
This commit is contained in:
34
util/init.js
34
util/init.js
@ -1,16 +1,30 @@
|
||||
function randomString(pattern, length){
|
||||
return Array.apply(null, {length: length}).map(() => (pattern[Math.floor(Math.random() * pattern.length)])).join('');
|
||||
return Array.apply(null, {length: length}).map(() => (pattern[Math.floor(Math.random() * pattern.length)])).join('')
|
||||
}
|
||||
|
||||
function generateCookie(){
|
||||
const jsessionid = randomString('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKMNOPQRSTUVWXYZ\\/+',176) + ':' + (new Date).getTime();
|
||||
const nuid = randomString('0123456789abcdefghijklmnopqrstuvwxyz',32);
|
||||
return {
|
||||
'JSESSIONID-WYYY': jsessionid,
|
||||
'_iuqxldmzr_': 32,
|
||||
'_ntes_nnid': nuid + ',' + (new Date).getTime(),
|
||||
'_ntes_nuid': nuid
|
||||
function completeCookie(cookie){
|
||||
let origin = (cookie || '').split(/;\s*/).map(element => (element.split('=')[0])), extra = []
|
||||
let now = (new Date).getTime()
|
||||
|
||||
if(!origin.includes('JSESSIONID-WYYY')){
|
||||
let expire = new Date(now + 1800000) //30 minutes
|
||||
let jessionid = randomString('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKMNOPQRSTUVWXYZ\\/+',176) + ':' + expire.getTime()
|
||||
extra.push(['JSESSIONID-WYYY=' + jessionid, 'Expires=' + expire.toGMTString()])
|
||||
}
|
||||
if(!origin.includes('_iuqxldmzr_')){
|
||||
let expire = new Date(now + 157680000000) //5 years
|
||||
extra.push(['_iuqxldmzr_=32', 'Expires=' + expire.toGMTString()])
|
||||
}
|
||||
if((!origin.includes('_ntes_nnid'))||(!origin.includes('_ntes_nuid'))){
|
||||
let expire = new Date(now + 3153600000000) //100 years
|
||||
let nnid = randomString('0123456789abcdefghijklmnopqrstuvwxyz',32) + ',' + now
|
||||
extra.push(['_ntes_nnid=' + nnid, 'Expires=' + expire.toGMTString()])
|
||||
extra.push(['_ntes_nuid=' + nnid.slice(0,32), 'Expires=' + expire.toGMTString()])
|
||||
}
|
||||
|
||||
return extra
|
||||
}
|
||||
|
||||
module.exports = generateCookie
|
||||
module.exports = {
|
||||
completeCookie
|
||||
}
|
Reference in New Issue
Block a user