Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1524 from NobeKanai/fix
Browse files Browse the repository at this point in the history
fix(playlist_track_all): fix inconsistent meaning of offset/limit between code and document
  • Loading branch information
Binaryify authored May 6, 2022
2 parents 65765ed + f4130b0 commit 4eef73d
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions module/playlist_track_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,24 @@ module.exports = (query, request) => {
s: query.s || 8,
}
//不放在data里面避免请求带上无用的数据
let limit = query.limit
let limit = parseInt(query.limit) || Infinity
let offset = parseInt(query.offset) || 0
let allOffset
let trackIds
let idsData = Object.create(null)

return request('POST', `https://music.163.com/api/v6/playlist/detail`, data, {
crypto: 'api',
cookie: query.cookie,
proxy: query.proxy,
realIP: query.realIP,
}).then((res) => {
const ids = []
let trackIds = res.body.playlist.trackIds
if (typeof limit === 'undefined') {
limit = trackIds.length
}
// 若offset超出最大偏移量则重置为最大偏移量
allOffset = trackIds.length / limit - 1
if (offset > allOffset) {
offset = allOffset
}
trackIds.forEach((item, index) => {
if (index >= limit * offset && index < limit * (offset + 1)) {
ids.push(item.id)
}
})
idsData = {
c: '[' + ids.map((id) => '{"id":' + id + '}').join(',') + ']',
let idsData = {
c:
'[' +
trackIds
.slice(offset, offset + limit)
.map((item) => '{"id":' + item.id + '}')
.join(',') +
']',
}

return request(
Expand Down

2 comments on commit 4eef73d

@vercel
Copy link

@vercel vercel bot commented on 4eef73d May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 4eef73d May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

netease-cloud-music-api – ./docs

netease-cloud-music-api-git-master-binaryify.vercel.app
neteasecloudmusicapi.vercel.app

Please sign in to comment.