WIP
This commit is contained in:
+29
-2
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user