Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import { type AppBskyFeedDefs, type AppBskyFeedGetActorLikes as GetActorLikes, type AtpAgent,} from '@atproto/api'
import {type FeedAPI, type FeedAPIResponse} from './types'
export class LikesFeedAPI implements FeedAPI { agent: AtpAgent params: GetActorLikes.QueryParams
constructor({ agent, feedParams, }: { agent: AtpAgent feedParams: GetActorLikes.QueryParams }) { this.agent = agent this.params = feedParams }
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> { const res = await this.agent.getActorLikes({ ...this.params, limit: 1, }) return res.data.feed[0] }
async fetch({ cursor, limit, }: { cursor: string | undefined limit: number }): Promise<FeedAPIResponse> { const res = await this.agent.getActorLikes({ ...this.params, cursor, limit, }) if (res.success) { // HACKFIX: the API incorrectly returns a cursor when there are no items -sfn const isEmptyPage = res.data.feed.length === 0 return { cursor: isEmptyPage ? undefined : res.data.cursor, feed: res.data.feed, } } return { feed: [], } }}