This commit is contained in:
Eric Bailey
2026-04-30 19:02:12 +01:00
parent 23569c3b28
commit 802a6b9a7d
4 changed files with 36 additions and 5 deletions
+29 -2
View File
@@ -8,7 +8,7 @@ import {
type AppBskyFeedPost,
AtUri,
BlobRef,
type BskyAgent,
BskyAgent,
type ComAtprotoLabelDefs,
type ComAtprotoRepoApplyWrites,
type ComAtprotoRepoStrongRef,
@@ -41,6 +41,10 @@ import {
} from '#/view/com/composer/state/composer'
import {createGIFDescription} from '../gif-alt-text'
import {uploadBlob} from './upload-blob'
import {
BLUESKY_PROXY_HEADER,
BSKY_SERVICE,
} from '#/lib/constants'
export {uploadBlob}
@@ -402,7 +406,7 @@ async function resolveMedia(
}
}
if (embedDraft.link) {
const resolvedLink = await fetchResolveLinkQuery(
const resolvedLink = await specialResolveLink(
queryClient,
agent,
embedDraft.link.uri,
@@ -445,6 +449,29 @@ async function resolveMedia(
return undefined
}
async function specialResolveLink(qc: QueryClient, agent: BskyAgent, uri: string): Promise<any> {
const resolved = await fetchResolveLinkQuery(
qc,
agent,
uri,
)
if (resolved.type !== 'external') return resolved
// @ts-ignore
if (!resolved.associatedRecord) return resolved
const pub = new BskyAgent({service: BSKY_SERVICE})
pub.configureProxy(BLUESKY_PROXY_HEADER.get())
// @ts-ignore
const urip = new AtUri(resolved.associatedRecord as string)
console.log(urip)
const res = await pub.com.atproto.repo.getRecord({
repo: urip.host,
collection: urip.collection,
rkey: urip.rkey,
})
console.log(res)
return resolved
}
async function resolveRecord(
agent: BskyAgent,
queryClient: QueryClient,
+2
View File
@@ -34,6 +34,7 @@ type ResolvedExternalLink = {
title: string
description: string
thumb: ComposerImage | undefined
associatedRecord?: {uri: string; cid: string}
}
type ResolvedPostRecord = {
@@ -239,6 +240,7 @@ async function resolveExternal(
title: result.title ?? '',
description: result.description ?? '',
thumb: result.image ? await imageToThumb(result.image) : undefined,
associatedRecord: result.associatedRecord,
}
}
+3 -3
View File
@@ -108,9 +108,9 @@ export const STAGING_LINK_META_PROXY =
export const PROD_LINK_META_PROXY = 'https://cardyb.bsky.app/v1/extract?url='
export function LINK_META_PROXY(serviceUrl: string) {
if (IS_PROD_SERVICE(serviceUrl)) {
return PROD_LINK_META_PROXY
}
// if (IS_PROD_SERVICE(serviceUrl)) {
// return PROD_LINK_META_PROXY
// }
return STAGING_LINK_META_PROXY
}
+2
View File
@@ -22,6 +22,7 @@ export interface LinkMeta {
title?: string
description?: string
image?: string
associatedRecord?: {uri: string; cid: string}
}
export async function getLinkMeta(
@@ -92,6 +93,7 @@ export async function getLinkMeta(
if (shouldFollowRedirect) {
meta.url = body.url
}
meta.associatedRecord = body.associated_record
} catch (e) {
// failed
console.error(e)