mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at verify-code 1.0 kB view raw
1import { 2 AppBskyFeedDefs, 3 AppBskyFeedGetListFeed as GetListFeed, 4 BskyAgent, 5} from '@atproto/api' 6 7import {FeedAPI, FeedAPIResponse} from './types' 8 9export class ListFeedAPI implements FeedAPI { 10 agent: BskyAgent 11 params: GetListFeed.QueryParams 12 13 constructor({ 14 agent, 15 feedParams, 16 }: { 17 agent: BskyAgent 18 feedParams: GetListFeed.QueryParams 19 }) { 20 this.agent = agent 21 this.params = feedParams 22 } 23 24 async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> { 25 const res = await this.agent.app.bsky.feed.getListFeed({ 26 ...this.params, 27 limit: 1, 28 }) 29 return res.data.feed[0] 30 } 31 32 async fetch({ 33 cursor, 34 limit, 35 }: { 36 cursor: string | undefined 37 limit: number 38 }): Promise<FeedAPIResponse> { 39 const res = await this.agent.app.bsky.feed.getListFeed({ 40 ...this.params, 41 cursor, 42 limit, 43 }) 44 if (res.success) { 45 return { 46 cursor: res.data.cursor, 47 feed: res.data.feed, 48 } 49 } 50 return { 51 feed: [], 52 } 53 } 54}