better sp embed
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
import {BskyAgent} from '@atproto/api'
|
import {BskyAgent} from '@atproto/api'
|
||||||
import {isBskyAppUrl} from '../strings/url-helpers'
|
|
||||||
import {extractBskyMeta} from './bsky'
|
|
||||||
import {LINK_META_PROXY} from 'lib/constants'
|
import {LINK_META_PROXY} from 'lib/constants'
|
||||||
import {getGiphyMetaUri} from 'lib/strings/embed-player'
|
import {getGiphyMetaUri} from 'lib/strings/embed-player'
|
||||||
|
import {
|
||||||
|
isBskyAppUrl,
|
||||||
|
isBskyStarterPackUrl,
|
||||||
|
isBskyStartUrl,
|
||||||
|
} from '../strings/url-helpers'
|
||||||
|
import {extractBskyMeta} from './bsky'
|
||||||
|
|
||||||
export enum LikelyType {
|
export enum LikelyType {
|
||||||
HTML,
|
HTML,
|
||||||
@@ -28,7 +33,7 @@ export async function getLinkMeta(
|
|||||||
url: string,
|
url: string,
|
||||||
timeout = 15e3,
|
timeout = 15e3,
|
||||||
): Promise<LinkMeta> {
|
): Promise<LinkMeta> {
|
||||||
if (isBskyAppUrl(url)) {
|
if (isBskyAppUrl(url) && !isBskyStartUrl(url) && !isBskyStarterPackUrl(url)) {
|
||||||
return extractBskyMeta(agent, url)
|
return extractBskyMeta(agent, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,13 @@ export function getStarterPackOgCard(
|
|||||||
rkey?: string,
|
rkey?: string,
|
||||||
) {
|
) {
|
||||||
if (typeof didOrStarterPack === 'string') {
|
if (typeof didOrStarterPack === 'string') {
|
||||||
|
// Used for link embeds so that we always keep the image up to date rather than using the uploaded one.
|
||||||
|
if (didOrStarterPack.startsWith('https://')) {
|
||||||
|
const parsed = parseStarterPackUri(didOrStarterPack)
|
||||||
|
if (!parsed) return null
|
||||||
|
return getStarterPackOgCard(parsed?.name, parsed?.rkey)
|
||||||
|
}
|
||||||
|
|
||||||
return `https://ogcard.cdn.bsky.app/start/${didOrStarterPack}/${rkey}`
|
return `https://ogcard.cdn.bsky.app/start/${didOrStarterPack}/${rkey}`
|
||||||
} else {
|
} else {
|
||||||
const rkey = new AtUri(didOrStarterPack.uri).rkey
|
const rkey = new AtUri(didOrStarterPack.uri).rkey
|
||||||
|
|||||||
@@ -151,6 +151,30 @@ export function isBskyListUrl(url: string): boolean {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isBskyStartUrl(url: string): boolean {
|
||||||
|
if (isBskyAppUrl(url)) {
|
||||||
|
try {
|
||||||
|
const urlp = new URL(url)
|
||||||
|
return /start\/(?<name>[^/]+)\/(?<rkey>[^/]+)/i.test(urlp.pathname)
|
||||||
|
} catch {
|
||||||
|
console.error('Unexpected error in isBskyListUrl()', url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isBskyStarterPackUrl(url: string): boolean {
|
||||||
|
if (isBskyAppUrl(url)) {
|
||||||
|
try {
|
||||||
|
const urlp = new URL(url)
|
||||||
|
return /starter-pack\/(?<name>[^/]+)\/(?<rkey>[^/]+)/i.test(urlp.pathname)
|
||||||
|
} catch {
|
||||||
|
console.error('Unexpected error in isBskyListUrl()', url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
export function isBskyDownloadUrl(url: string): boolean {
|
export function isBskyDownloadUrl(url: string): boolean {
|
||||||
if (isExternalUrl(url)) {
|
if (isExternalUrl(url)) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -2,12 +2,19 @@ import React, {useCallback} from 'react'
|
|||||||
import {StyleProp, View, ViewStyle} from 'react-native'
|
import {StyleProp, View, ViewStyle} from 'react-native'
|
||||||
import {Image} from 'expo-image'
|
import {Image} from 'expo-image'
|
||||||
import {AppBskyEmbedExternal} from '@atproto/api'
|
import {AppBskyEmbedExternal} from '@atproto/api'
|
||||||
|
import {msg} from '@lingui/macro'
|
||||||
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||||
import {shareUrl} from 'lib/sharing'
|
import {shareUrl} from 'lib/sharing'
|
||||||
import {parseEmbedPlayerFromUrl} from 'lib/strings/embed-player'
|
import {parseEmbedPlayerFromUrl} from 'lib/strings/embed-player'
|
||||||
import {toNiceDomain} from 'lib/strings/url-helpers'
|
import {getStarterPackOgCard} from 'lib/strings/starter-pack'
|
||||||
|
import {
|
||||||
|
isBskyStarterPackUrl,
|
||||||
|
isBskyStartUrl,
|
||||||
|
toNiceDomain,
|
||||||
|
} from 'lib/strings/url-helpers'
|
||||||
import {isNative} from 'platform/detection'
|
import {isNative} from 'platform/detection'
|
||||||
import {useExternalEmbedsPrefs} from 'state/preferences'
|
import {useExternalEmbedsPrefs} from 'state/preferences'
|
||||||
import {Link} from 'view/com/util/Link'
|
import {Link} from 'view/com/util/Link'
|
||||||
@@ -28,10 +35,15 @@ export const ExternalLinkEmbed = ({
|
|||||||
style?: StyleProp<ViewStyle>
|
style?: StyleProp<ViewStyle>
|
||||||
hideAlt?: boolean
|
hideAlt?: boolean
|
||||||
}) => {
|
}) => {
|
||||||
|
const {_} = useLingui()
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {isMobile} = useWebMediaQueries()
|
const {isMobile} = useWebMediaQueries()
|
||||||
const externalEmbedPrefs = useExternalEmbedsPrefs()
|
const externalEmbedPrefs = useExternalEmbedsPrefs()
|
||||||
|
|
||||||
|
const isStarterPack =
|
||||||
|
isBskyStartUrl(link.uri) || isBskyStarterPackUrl(link.uri)
|
||||||
|
const imageUri = isStarterPack ? getStarterPackOgCard(link.uri) : link.thumb
|
||||||
|
|
||||||
const embedPlayerParams = React.useMemo(() => {
|
const embedPlayerParams = React.useMemo(() => {
|
||||||
const params = parseEmbedPlayerFromUrl(link.uri)
|
const params = parseEmbedPlayerFromUrl(link.uri)
|
||||||
|
|
||||||
@@ -47,15 +59,19 @@ export const ExternalLinkEmbed = ({
|
|||||||
return (
|
return (
|
||||||
<View style={[a.flex_col, a.rounded_sm, a.overflow_hidden, a.mt_sm]}>
|
<View style={[a.flex_col, a.rounded_sm, a.overflow_hidden, a.mt_sm]}>
|
||||||
<LinkWrapper link={link} onOpen={onOpen} style={style}>
|
<LinkWrapper link={link} onOpen={onOpen} style={style}>
|
||||||
{link.thumb && !embedPlayerParams ? (
|
{imageUri && !embedPlayerParams ? (
|
||||||
<Image
|
<Image
|
||||||
style={{
|
style={{
|
||||||
aspectRatio: 1.91,
|
aspectRatio: 1.91,
|
||||||
borderTopRightRadius: 6,
|
borderTopRightRadius: 6,
|
||||||
borderTopLeftRadius: 6,
|
borderTopLeftRadius: 6,
|
||||||
}}
|
}}
|
||||||
source={{uri: link.thumb}}
|
source={{uri: imageUri}}
|
||||||
accessibilityIgnoresInvertColors
|
accessibilityIgnoresInvertColors
|
||||||
|
accessibilityLabel={isStarterPack ? link.title : undefined}
|
||||||
|
accessibilityHint={
|
||||||
|
isStarterPack ? _(msg`Navigate to starter pack`) : undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
{embedPlayerParams?.isGif ? (
|
{embedPlayerParams?.isGif ? (
|
||||||
@@ -63,6 +79,7 @@ export const ExternalLinkEmbed = ({
|
|||||||
) : embedPlayerParams ? (
|
) : embedPlayerParams ? (
|
||||||
<ExternalPlayer link={link} params={embedPlayerParams} />
|
<ExternalPlayer link={link} params={embedPlayerParams} />
|
||||||
) : undefined}
|
) : undefined}
|
||||||
|
{!isStarterPack ? (
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
a.flex_1,
|
a.flex_1,
|
||||||
@@ -92,6 +109,7 @@ export const ExternalLinkEmbed = ({
|
|||||||
</Text>
|
</Text>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
</View>
|
</View>
|
||||||
|
) : null}
|
||||||
</LinkWrapper>
|
</LinkWrapper>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user