Merge pull request #1524 from NobeKanai/fix

fix(playlist_track_all): fix inconsistent meaning of offset/limit between code and document
This commit is contained in:
binaryify 2022-05-06 20:41:26 +08:00 committed by GitHub
commit 4eef73db71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,11 +8,8 @@ module.exports = (query, request) => {
s: query.s || 8, s: query.s || 8,
} }
//不放在data里面避免请求带上无用的数据 //不放在data里面避免请求带上无用的数据
let limit = query.limit let limit = parseInt(query.limit) || Infinity
let offset = parseInt(query.offset) || 0 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, { return request('POST', `https://music.163.com/api/v6/playlist/detail`, data, {
crypto: 'api', crypto: 'api',
@ -20,23 +17,15 @@ module.exports = (query, request) => {
proxy: query.proxy, proxy: query.proxy,
realIP: query.realIP, realIP: query.realIP,
}).then((res) => { }).then((res) => {
const ids = []
let trackIds = res.body.playlist.trackIds let trackIds = res.body.playlist.trackIds
if (typeof limit === 'undefined') { let idsData = {
limit = trackIds.length c:
} '[' +
// 若offset超出最大偏移量则重置为最大偏移量 trackIds
allOffset = trackIds.length / limit - 1 .slice(offset, offset + limit)
if (offset > allOffset) { .map((item) => '{"id":' + item.id + '}')
offset = allOffset .join(',') +
} ']',
trackIds.forEach((item, index) => {
if (index >= limit * offset && index < limit * (offset + 1)) {
ids.push(item.id)
}
})
idsData = {
c: '[' + ids.map((id) => '{"id":' + id + '}').join(',') + ']',
} }
return request( return request(