Better starterpack embed (#4659)

This commit is contained in:
Hailey
2024-06-26 17:24:33 -07:00
committed by GitHub
parent da4dfeb9cf
commit 878b0476dd
6 changed files with 103 additions and 32 deletions
+5 -3
View File
@@ -1,8 +1,10 @@
import {BskyAgent} from '@atproto/api'
import {isBskyAppUrl} from '../strings/url-helpers'
import {extractBskyMeta} from './bsky'
import {LINK_META_PROXY} from 'lib/constants'
import {getGiphyMetaUri} from 'lib/strings/embed-player'
import {parseStarterPackUri} from 'lib/strings/starter-pack'
import {isBskyAppUrl} from '../strings/url-helpers'
import {extractBskyMeta} from './bsky'
export enum LikelyType {
HTML,
@@ -28,7 +30,7 @@ export async function getLinkMeta(
url: string,
timeout = 15e3,
): Promise<LinkMeta> {
if (isBskyAppUrl(url)) {
if (isBskyAppUrl(url) && !parseStarterPackUri(url)) {
return extractBskyMeta(agent, url)
}
+23
View File
@@ -0,0 +1,23 @@
import {logger} from '#/logger'
import {startUriToStarterPackUri} from 'lib/strings/starter-pack'
export async function resolveShortLink(shortLink: string) {
const controller = new AbortController()
const to = setTimeout(() => controller.abort(), 2e3)
try {
const res = await fetch(shortLink, {
method: 'GET',
signal: controller.signal,
})
if (res.status !== 200) {
return shortLink
}
return startUriToStarterPackUri(res.url)
} catch (e: unknown) {
logger.error('Failed to resolve short link', {safeMessage: e})
return null
} finally {
clearTimeout(to)
}
}