diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index 9f1dae12e1..82623e5820 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -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 { + 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, diff --git a/src/lib/api/resolve.ts b/src/lib/api/resolve.ts index e6d21845fd..412be4fdd3 100644 --- a/src/lib/api/resolve.ts +++ b/src/lib/api/resolve.ts @@ -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, } } diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 8364cd2f6c..e40f97f79d 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -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 } diff --git a/src/lib/link-meta/link-meta.ts b/src/lib/link-meta/link-meta.ts index 3d9a695f05..327de6dcee 100644 --- a/src/lib/link-meta/link-meta.ts +++ b/src/lib/link-meta/link-meta.ts @@ -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)