add bot custom feed
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
This commit is contained in:
43
at/feed-generator/src/algos/cmd.ts
Normal file
43
at/feed-generator/src/algos/cmd.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { InvalidRequestError } from '@atproto/xrpc-server'
|
||||
import { QueryParams } from '../lexicon/types/app/bsky/feed/getFeedSkeleton'
|
||||
import { AppContext } from '../config'
|
||||
|
||||
// max 15 chars
|
||||
export const shortname = 'cmd'
|
||||
|
||||
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 [indexedAt, cid] = params.cursor.split('::')
|
||||
if (!indexedAt || !cid) {
|
||||
throw new InvalidRequestError('malformed cursor')
|
||||
}
|
||||
const timeStr = new Date(parseInt(indexedAt, 10)).toISOString()
|
||||
builder = builder
|
||||
.where('post.indexedAt', '<', timeStr)
|
||||
.orWhere((qb) => qb.where('post.indexedAt', '=', timeStr))
|
||||
.where('post.cid', '<', cid)
|
||||
}
|
||||
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()}::${last.cid}`
|
||||
}
|
||||
|
||||
return {
|
||||
cursor,
|
||||
feed,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user