Fetch link previews from RQ (#5608)

Co-authored-by: Mary <git@mary.my.id>
Co-authored-by: Hailey <me@haileyok.com>
This commit is contained in:
dan
2024-10-08 09:02:58 +09:00
committed by GitHub
parent dd8be2e939
commit c06040cc20
17 changed files with 494 additions and 520 deletions
+43 -6
View File
@@ -1,4 +1,4 @@
import {ComAtprotoRepoStrongRef} from '@atproto/api'
import {AppBskyActorDefs, ComAtprotoRepoStrongRef} from '@atproto/api'
import {AtUri} from '@atproto/api'
import {BskyAgent} from '@atproto/api'
@@ -33,12 +33,32 @@ type ResolvedExternalLink = {
thumb: ComposerImage | undefined
}
type ResolvedRecord = {
type ResolvedPostRecord = {
type: 'record'
record: ComAtprotoRepoStrongRef.Main
kind: 'post'
meta: {
text: string
indexedAt: string
author: AppBskyActorDefs.ProfileViewBasic
}
}
type ResolvedLink = ResolvedExternalLink | ResolvedRecord
type ResolvedOtherRecord = {
type: 'record'
record: ComAtprotoRepoStrongRef.Main
kind: 'other'
meta: {
// We should replace this with a hydrated record (e.g. feed, list, starter pack)
// and change the composer preview to use the actual post embed components:
title: string
}
}
export type ResolvedLink =
| ResolvedExternalLink
| ResolvedPostRecord
| ResolvedOtherRecord
export async function resolveLink(
agent: BskyAgent,
@@ -57,6 +77,8 @@ export async function resolveLink(
cid: result.cid,
uri: result.uri,
},
kind: 'post',
meta: result,
}
}
if (isBskyCustomFeedUrl(uri)) {
@@ -64,7 +86,12 @@ export async function resolveLink(
const result = await getFeedAsEmbed(agent, fetchDid, uri)
return {
type: 'record',
record: result.embed!.record, // TODO: Fix types.
record: result.embed!.record,
kind: 'other',
meta: {
// TODO: Include hydrated content instead.
title: result.meta!.title!,
},
}
}
if (isBskyListUrl(uri)) {
@@ -72,7 +99,12 @@ export async function resolveLink(
const result = await getListAsEmbed(agent, fetchDid, uri)
return {
type: 'record',
record: result.embed!.record, // TODO: Fix types.
record: result.embed!.record,
kind: 'other',
meta: {
// TODO: Include hydrated content instead.
title: result.meta!.title!,
},
}
}
if (isBskyStartUrl(uri) || isBskyStarterPackUrl(uri)) {
@@ -80,7 +112,12 @@ export async function resolveLink(
const result = await getStarterPackAsEmbed(agent, fetchDid, uri)
return {
type: 'record',
record: result.embed!.record, // TODO: Fix types.
record: result.embed!.record,
kind: 'other',
meta: {
// TODO: Include hydrated content instead.
title: result.meta!.title!,
},
}
}
return resolveExternal(agent, uri)