mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2026-03-03 16:49:20 +00:00
Add request quota system
This commit is contained in:
@@ -45,16 +45,22 @@ class Timeline {
|
||||
: this.type === "igtv" ? collectors.fetchIGTVPage
|
||||
: null
|
||||
const after = this.page_info ? this.page_info.end_cursor : ""
|
||||
return method(this.user.data.id, after).then(page => {
|
||||
return method(this.user.data.id, after).then(({result: page, fromCache}) => {
|
||||
const quotaUsed = fromCache ? 0 : 1
|
||||
this.addPage(page)
|
||||
return this.pages.slice(-1)[0]
|
||||
return {page: this.pages.slice(-1)[0], quotaUsed}
|
||||
})
|
||||
}
|
||||
|
||||
async fetchUpToPage(index) {
|
||||
let quotaUsed = 0
|
||||
while (this.pages[index] === undefined && this.hasNextPage()) {
|
||||
await this.fetchNextPage()
|
||||
const result = await this.fetchNextPage()
|
||||
if (typeof result !== "symbol") {
|
||||
quotaUsed += result.quotaUsed
|
||||
}
|
||||
}
|
||||
return quotaUsed
|
||||
}
|
||||
|
||||
addPage(page) {
|
||||
|
||||
@@ -32,7 +32,7 @@ class TimelineEntry extends TimelineBaseMethods {
|
||||
|
||||
async update() {
|
||||
return collectors.fetchShortcodeData(this.data.shortcode).then(data => {
|
||||
this.applyN3(data)
|
||||
this.applyN3(data.result)
|
||||
}).catch(error => {
|
||||
console.error("TimelineEntry could not self-update; trying to continue anyway...")
|
||||
console.error("E:", error)
|
||||
|
||||
Reference in New Issue
Block a user