mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-09-05 23:47:43 +08:00
⚡ Perf: optimize imgur album list speed
This commit is contained in:
@@ -60,35 +60,24 @@ class ImgurApi {
|
|||||||
const result = [] as any[]
|
const result = [] as any[]
|
||||||
do {
|
do {
|
||||||
res = await got(
|
res = await got(
|
||||||
`${this.baseUrl}/account/${this.userName}/albums/ids/${initPage}`,
|
`${this.baseUrl}/account/${this.userName}/albums/${initPage}`,
|
||||||
getOptions('GET', this.tokenHeaders, undefined, 'json', undefined, undefined, this.proxy)
|
getOptions('GET', this.tokenHeaders, undefined, 'json', undefined, undefined, this.proxy)
|
||||||
) as any
|
) as any
|
||||||
if (res.statusCode === 200 && res.body.success) {
|
if (!(res.statusCode === 200 && res.body.success)) {
|
||||||
res.body.data.forEach((item: any) => {
|
|
||||||
result.push(item)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
result.push(...res.body.data)
|
||||||
initPage++
|
initPage++
|
||||||
} while (res.body.data.length > 0)
|
} while (res.body.data.length > 0)
|
||||||
const finalResult = [] as any[]
|
const finalResult = [] as any[]
|
||||||
for (let i = 0; i < result.length; i++) {
|
for (let i = 0; i < result.length; i++) {
|
||||||
const item = result[i]
|
const item = result[i]
|
||||||
const res = await got(
|
|
||||||
`${this.baseUrl}/account/${this.userName}/album/${item}`,
|
|
||||||
getOptions('GET', this.tokenHeaders, undefined, 'json', undefined, undefined, this.proxy)
|
|
||||||
) as any
|
|
||||||
if (res.statusCode === 200 && res.body.success) {
|
|
||||||
finalResult.push({
|
finalResult.push({
|
||||||
...res.body.data,
|
...item,
|
||||||
Name: res.body.data.title,
|
Name: item.title,
|
||||||
Location: res.body.data.id,
|
Location: item.id,
|
||||||
CreationDate: res.body.data.datetime
|
CreationDate: item.datetime
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finalResult.push({
|
finalResult.push({
|
||||||
Name: '全部',
|
Name: '全部',
|
||||||
|
|||||||
Reference in New Issue
Block a user