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

fix(playlist_track_all): fix inconsistent meaning of offset/limit between code and document #1524

Merged
merged 1 commit into from
May 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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