-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscala-feed.ts
36 lines (30 loc) · 921 Bytes
/
scala-feed.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { QueryParams } from '../lexicon/types/app/bsky/feed/getFeedSkeleton'
import { AppContext } from '../config'
// max 15 chars
export const shortname = 'scala-feed'
// not much of an algorithm, it just fetches the ids from db and returns them to user
export const handler = async (ctx: AppContext, params: QueryParams) => {
let builder = ctx.db
.selectFrom('post')
.selectAll()
.orderBy('indexedAt', 'desc')
.orderBy('cid', 'desc')
.limit(params.limit)
if (params.cursor) {
const timeStr = new Date(parseInt(params.cursor, 10)).toISOString()
builder = builder.where('post.indexedAt', '<', timeStr)
}
const res = await builder.execute()
const feed = res.map((row) => ({
post: row.uri,
}));
let cursor: string | undefined
const last = res.at(-1)
if (last) {
cursor = new Date(last.indexedAt).getTime().toString(10)
}
return {
cursor,
feed,
}
}