WIP
This commit is contained in:
+29
-2
@@ -8,7 +8,7 @@ import {
|
|||||||
type AppBskyFeedPost,
|
type AppBskyFeedPost,
|
||||||
AtUri,
|
AtUri,
|
||||||
BlobRef,
|
BlobRef,
|
||||||
type BskyAgent,
|
BskyAgent,
|
||||||
type ComAtprotoLabelDefs,
|
type ComAtprotoLabelDefs,
|
||||||
type ComAtprotoRepoApplyWrites,
|
type ComAtprotoRepoApplyWrites,
|
||||||
type ComAtprotoRepoStrongRef,
|
type ComAtprotoRepoStrongRef,
|
||||||
@@ -41,6 +41,10 @@ import {
|
|||||||
} from '#/view/com/composer/state/composer'
|
} from '#/view/com/composer/state/composer'
|
||||||
import {createGIFDescription} from '../gif-alt-text'
|
import {createGIFDescription} from '../gif-alt-text'
|
||||||
import {uploadBlob} from './upload-blob'
|
import {uploadBlob} from './upload-blob'
|
||||||
|
import {
|
||||||
|
BLUESKY_PROXY_HEADER,
|
||||||
|
BSKY_SERVICE,
|
||||||
|
} from '#/lib/constants'
|
||||||
|
|
||||||
export {uploadBlob}
|
export {uploadBlob}
|
||||||
|
|
||||||
@@ -402,7 +406,7 @@ async function resolveMedia(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (embedDraft.link) {
|
if (embedDraft.link) {
|
||||||
const resolvedLink = await fetchResolveLinkQuery(
|
const resolvedLink = await specialResolveLink(
|
||||||
queryClient,
|
queryClient,
|
||||||
agent,
|
agent,
|
||||||
embedDraft.link.uri,
|
embedDraft.link.uri,
|
||||||
@@ -445,6 +449,29 @@ async function resolveMedia(
|
|||||||
return undefined
|
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(
|
async function resolveRecord(
|
||||||
agent: BskyAgent,
|
agent: BskyAgent,
|
||||||
queryClient: QueryClient,
|
queryClient: QueryClient,
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ type ResolvedExternalLink = {
|
|||||||
title: string
|
title: string
|
||||||
description: string
|
description: string
|
||||||
thumb: ComposerImage | undefined
|
thumb: ComposerImage | undefined
|
||||||
|
associatedRecord?: {uri: string; cid: string}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResolvedPostRecord = {
|
type ResolvedPostRecord = {
|
||||||
@@ -239,6 +240,7 @@ async function resolveExternal(
|
|||||||
title: result.title ?? '',
|
title: result.title ?? '',
|
||||||
description: result.description ?? '',
|
description: result.description ?? '',
|
||||||
thumb: result.image ? await imageToThumb(result.image) : undefined,
|
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 const PROD_LINK_META_PROXY = 'https://cardyb.bsky.app/v1/extract?url='
|
||||||
|
|
||||||
export function LINK_META_PROXY(serviceUrl: string) {
|
export function LINK_META_PROXY(serviceUrl: string) {
|
||||||
if (IS_PROD_SERVICE(serviceUrl)) {
|
// if (IS_PROD_SERVICE(serviceUrl)) {
|
||||||
return PROD_LINK_META_PROXY
|
// return PROD_LINK_META_PROXY
|
||||||
}
|
// }
|
||||||
|
|
||||||
return STAGING_LINK_META_PROXY
|
return STAGING_LINK_META_PROXY
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export interface LinkMeta {
|
|||||||
title?: string
|
title?: string
|
||||||
description?: string
|
description?: string
|
||||||
image?: string
|
image?: string
|
||||||
|
associatedRecord?: {uri: string; cid: string}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getLinkMeta(
|
export async function getLinkMeta(
|
||||||
@@ -92,6 +93,7 @@ export async function getLinkMeta(
|
|||||||
if (shouldFollowRedirect) {
|
if (shouldFollowRedirect) {
|
||||||
meta.url = body.url
|
meta.url = body.url
|
||||||
}
|
}
|
||||||
|
meta.associatedRecord = body.associated_record
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// failed
|
// failed
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
|||||||
Reference in New Issue
Block a user