Skip to content

Commit

Permalink
refactor: use native bluesky type narrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Oct 25, 2024
1 parent a03b804 commit 6207b71
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions modules/runtime/server/_social/bluesky.get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { AppBskyFeedPost, AppBskyEmbedImages } from '@atproto/api'
import { AtpAgent } from '@atproto/api'
import { AppBskyEmbedImages, AppBskyFeedPost, AtpAgent } from '@atproto/api'
import MagicString from 'magic-string'

export default defineLazyEventHandler(async () => {
Expand All @@ -15,17 +14,10 @@ export default defineLazyEventHandler(async () => {
const posts = await agent.getAuthorFeed({ actor: identifier })
return Promise.all(
posts.data.feed
.filter(
p =>
'$type' in p.post.record
&& p.post.record.$type === 'app.bsky.feed.post'
&& p.post.author.handle === identifier
&& p.post.embed?.$type !== 'app.bsky.embed.record#view'
&& !p.reply,
)
.filter(p => AppBskyFeedPost.isRecord(p.post.record) && p.post.author.handle === identifier && !p.reply && (!p.post.embed || AppBskyEmbedImages.isMain(p.post.embed)))
.map(p => {
const post = p.post.record as AppBskyFeedPost.Record
const embed = p.post.embed as AppBskyEmbedImages.Main | undefined
const embed = AppBskyEmbedImages.isMain(p.post.embed) ? p.post.embed : undefined
const text = new MagicString(post.text)
for (const facet of post.facets || []) {
const startIndex = [...post.text].findIndex(
Expand Down

0 comments on commit 6207b71

Please sign in to comment.