Skip to content

Commit

Permalink
fix(provider/kuwo): rework csrf token generator
Browse files Browse the repository at this point in the history
Signed-off-by: Tianling Shen <[email protected]>
  • Loading branch information
1715173329 committed Jul 9, 2023
1 parent b81a7c0 commit 909902d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ module.exports = {
.once('finish', () => resolve(digest.read()));
}),
},
random: {
hex: (length) =>
crypto
.randomBytes(Math.ceil(length / 2))
.toString('hex')
.slice(0, length),
},
};

try {
Expand Down
6 changes: 3 additions & 3 deletions src/provider/kuwo.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ const search = (info) => {
const keyword = encodeURIComponent(info.keyword.replace(' - ', ' '));
const url = `http://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key=${keyword}&pn=1&rn=30`;

const token = Math.random().toString(16).slice(-11).toUpperCase();
const token = crypto.random.hex(32).toUpperCase();
return request('GET', url, {
referer: `http://www.kuwo.cn/search/list?key=${keyword}`,
csrf: token,
cookie: `kw_token=${token}`,
cross: crypto.md5.digest(token),
cookie: `Hm_token=${token}`,
})
.then((response) => response.json())
.then((jsonBody) => {
Expand Down

0 comments on commit 909902d

Please sign in to comment.