···
type ComAtprotoRepoStrongRef,
+
import { TID } from '@atproto/common-web'
import * as dcbor from '@ipld/dag-cbor'
+
import { t } from '@lingui/macro'
+
import { type QueryClient } from '@tanstack/react-query'
+
import { sha256 } from 'js-sha256'
+
import { CID } from 'multiformats/cid'
import * as Hasher from 'multiformats/hashes/hasher'
+
import { isNetworkError } from '#/lib/strings/errors'
+
import { shortenLinks, stripInvalidMentions, parseMarkdownLinks } from '#/lib/strings/rich-text-manip'
+
import { logger } from '#/logger'
+
import { compressImage } from '#/state/gallery'
···
} from '#/view/com/composer/state/composer'
+
import { createGIFDescription } from '../gif-alt-text'
+
import { uploadBlob } from './upload-blob'
···
if (draft.labels.length) {
$type: 'com.atproto.label.defs#selfLabels',
+
values: draft.labels.map(val => ({ val })),
···
async function resolveRT(agent: BskyAgent, richtext: RichText) {
···
.replace(/^(\s*\n)+/, '')
// Trim any trailing whitespace.
+
const { text: parsedText, facets: markdownFacets } =
+
parseMarkdownLinks(trimmedText)
+
let rt = new RichText({ text: parsedText }, { cleanNewlines: true })
await rt.detectFacets(agent)
+
if (markdownFacets.length > 0) {
+
const nonOverlapping = (rt.facets || []).filter(f => {
+
return !markdownFacets.some(mf => {
+
(f.index.byteStart >= mf.index.byteStart &&
+
f.index.byteStart < mf.index.byteEnd) ||
+
(f.index.byteEnd > mf.index.byteStart &&
+
f.index.byteEnd <= mf.index.byteEnd) ||
+
(mf.index.byteStart >= f.index.byteStart &&
+
mf.index.byteStart < f.index.byteEnd)
+
rt.facets = [...nonOverlapping, ...markdownFacets].sort(
+
(a, b) => a.index.byteStart - b.index.byteStart,
rt = stripInvalidMentions(rt)
···
const images: AppBskyEmbedImages.Image[] = await Promise.all(
imagesDraft.map(async (image, i) => {
logger.debug(`Compressing image #${i}`)
+
const { path, width, height, mime } = await compressImage(image)
logger.debug(`Uploading image #${i}`)
const res = await uploadBlob(agent, path, mime)
+
aspectRatio: { width, height },
···
.filter(caption => caption.lang !== '')
+
const { data } = await agent.uploadBlob(caption.file, {
+
return { lang: caption.lang, file: data.blob }
···
// aspect ratio values must be >0 - better to leave as unset otherwise
// posting will fail if aspect ratio is set to 0
+
const aspectRatio = width > 0 && height > 0 ? { width, height } : undefined
···
let blob: BlobRef | undefined
onStateChange?.(t`Uploading link thumbnail...`)
+
const { path, mime } = resolvedGif.thumb.source
const response = await uploadBlob(agent, path, mime)
blob = response.data.blob
···
let blob: BlobRef | undefined
if (resolvedLink.thumb) {
onStateChange?.(t`Uploading link thumbnail...`)
+
const { path, mime } = resolvedLink.thumb.source
const response = await uploadBlob(agent, path, mime)
blob = response.data.blob