simplify further
This commit is contained in:
@@ -2,11 +2,8 @@ import {BskyAgent} from '@atproto/api'
|
||||
|
||||
import {LINK_META_PROXY} from 'lib/constants'
|
||||
import {getGiphyMetaUri} from 'lib/strings/embed-player'
|
||||
import {
|
||||
isBskyAppUrl,
|
||||
isBskyStarterPackUrl,
|
||||
isBskyStartUrl,
|
||||
} from '../strings/url-helpers'
|
||||
import {parseStarterPackUri} from 'lib/strings/starter-pack'
|
||||
import {isBskyAppUrl} from '../strings/url-helpers'
|
||||
import {extractBskyMeta} from './bsky'
|
||||
|
||||
export enum LikelyType {
|
||||
@@ -33,7 +30,7 @@ export async function getLinkMeta(
|
||||
url: string,
|
||||
timeout = 15e3,
|
||||
): Promise<LinkMeta> {
|
||||
if (isBskyAppUrl(url) && !isBskyStartUrl(url) && !isBskyStarterPackUrl(url)) {
|
||||
if (isBskyAppUrl(url) && !parseStarterPackUri(url)) {
|
||||
return extractBskyMeta(agent, url)
|
||||
}
|
||||
|
||||
|
||||
@@ -83,12 +83,6 @@ export function getStarterPackOgCard(
|
||||
rkey?: 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.
|
||||
const parsed = parseStarterPackUri(didOrStarterPack)
|
||||
if (parsed) {
|
||||
return getStarterPackOgCard(parsed?.name, parsed?.rkey)
|
||||
}
|
||||
|
||||
return `https://ogcard.cdn.bsky.app/start/${didOrStarterPack}/${rkey}`
|
||||
} else {
|
||||
const rkey = new AtUri(didOrStarterPack.uri).rkey
|
||||
|
||||
@@ -151,30 +151,6 @@ export function isBskyListUrl(url: string): boolean {
|
||||
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 {
|
||||
if (isExternalUrl(url)) {
|
||||
return false
|
||||
|
||||
@@ -9,12 +9,11 @@ import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||
import {shareUrl} from 'lib/sharing'
|
||||
import {parseEmbedPlayerFromUrl} from 'lib/strings/embed-player'
|
||||
import {getStarterPackOgCard} from 'lib/strings/starter-pack'
|
||||
import {
|
||||
isBskyStarterPackUrl,
|
||||
isBskyStartUrl,
|
||||
toNiceDomain,
|
||||
} from 'lib/strings/url-helpers'
|
||||
getStarterPackOgCard,
|
||||
parseStarterPackUri,
|
||||
} from 'lib/strings/starter-pack'
|
||||
import {toNiceDomain} from 'lib/strings/url-helpers'
|
||||
import {isNative} from 'platform/detection'
|
||||
import {useExternalEmbedsPrefs} from 'state/preferences'
|
||||
import {Link} from 'view/com/util/Link'
|
||||
@@ -40,9 +39,10 @@ export const ExternalLinkEmbed = ({
|
||||
const {isMobile} = useWebMediaQueries()
|
||||
const externalEmbedPrefs = useExternalEmbedsPrefs()
|
||||
|
||||
const isStarterPack =
|
||||
isBskyStartUrl(link.uri) || isBskyStarterPackUrl(link.uri)
|
||||
const imageUri = isStarterPack ? getStarterPackOgCard(link.uri) : link.thumb
|
||||
const starterPackParsed = parseStarterPackUri(link.uri)
|
||||
const imageUri = starterPackParsed
|
||||
? getStarterPackOgCard(starterPackParsed.name, starterPackParsed.rkey)
|
||||
: link.thumb
|
||||
|
||||
const embedPlayerParams = React.useMemo(() => {
|
||||
const params = parseEmbedPlayerFromUrl(link.uri)
|
||||
@@ -68,9 +68,9 @@ export const ExternalLinkEmbed = ({
|
||||
}}
|
||||
source={{uri: imageUri}}
|
||||
accessibilityIgnoresInvertColors
|
||||
accessibilityLabel={isStarterPack ? link.title : undefined}
|
||||
accessibilityLabel={starterPackParsed ? link.title : undefined}
|
||||
accessibilityHint={
|
||||
isStarterPack ? _(msg`Navigate to starter pack`) : undefined
|
||||
starterPackParsed ? _(msg`Navigate to starter pack`) : undefined
|
||||
}
|
||||
/>
|
||||
) : undefined}
|
||||
@@ -79,7 +79,7 @@ export const ExternalLinkEmbed = ({
|
||||
) : embedPlayerParams ? (
|
||||
<ExternalPlayer link={link} params={embedPlayerParams} />
|
||||
) : undefined}
|
||||
{!isStarterPack ? (
|
||||
{!starterPackParsed ? (
|
||||
<View
|
||||
style={[
|
||||
a.flex_1,
|
||||
|
||||
Reference in New Issue
Block a user