forked from Mastodon/mastoradio-la-radio-di-mastodon
fix statuses generator regression
This commit is contained in:
parent
ae187a96ef
commit
2c78fb6d3b
11
src/util.js
11
src/util.js
|
@ -51,18 +51,24 @@ export async function* mkStatusesIterator(initialLink) {
|
|||
if (latestPreviousFetch + 5 * minute < now) {
|
||||
console.log('fetch newer')
|
||||
const previous = await fetchTimeline(previousLink)
|
||||
console.log(`${previous.length} newers`)
|
||||
|
||||
latestPreviousFetch = now
|
||||
|
||||
if (previous.statuses.length) {
|
||||
buffer.unshift(...previous.statuses)
|
||||
previousLink = previous.links.prev
|
||||
latestPreviousFetch = now
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer.length === 0) {
|
||||
console.log('fetch older')
|
||||
const next = await fetchTimeline(nextLink)
|
||||
|
||||
if (next.statuses.length) {
|
||||
buffer.push(...next.statuses)
|
||||
nextLink = next.links.next
|
||||
}
|
||||
}
|
||||
|
||||
yield buffer.shift()
|
||||
}
|
||||
|
@ -96,6 +102,7 @@ export async function* mkTracksIterator(domain, hashtags) {
|
|||
}
|
||||
|
||||
export async function fetchTimeline(url) {
|
||||
console.log(`fetching ${url}`)
|
||||
const response = await fetch(url)
|
||||
const statuses = await response.json()
|
||||
|
||||
|
|
Loading…
Reference in New Issue