Better starterpack embed (#4659)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user