forked from Binaryify/NeteaseCloudMusicApi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allocate js cookie in middleware, update res cookie distribution
- Loading branch information
Showing
6 changed files
with
40 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters