Skip to content

Commit

Permalink
feat(src/hook): add custom NCM cookie support
Browse files Browse the repository at this point in the history
Signed-off-by: Tianling Shen <[email protected]>
  • Loading branch information
1715173329 committed Jun 2, 2023
1 parent 12769fa commit dd92fe6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const LOCAL_VIP_UID = (process.env.LOCAL_VIP_UID || '')
.split(',')
.map((str) => parseInt(str))
.filter((num) => !Number.isNaN(num));
const NCM_COOKIE = process.env.NCM_COOKIE || null;

const hook = {
request: {
Expand Down Expand Up @@ -182,6 +183,18 @@ hook.request.before = (ctx) => {
ctx.netease = netease;
// console.log(netease.path, netease.param)

if (netease.path.includes('song/enhance') && NCM_COOKIE) {
req.headers.cookie = [
`MUSIC_U=${NCM_COOKIE}`,
req.headers.cookie.replace(
/\s*MUSIC_\w=[^\s;]+;*/g,
''
),
]
.filter((line) => line)
.join('; ');
}

if (
netease.path === '/api/song/enhance/download/url' ||
netease.path === '/api/song/enhance/download/url/v1'
Expand Down

0 comments on commit dd92fe6

Please sign in to comment.