[APP-2066] Migrate from Tenor to KLIPY (#10240)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+31
-3
@@ -190,16 +190,44 @@ export async function resolveGif(
|
||||
agent: BskyAgent,
|
||||
gif: Gif,
|
||||
): Promise<ResolvedExternalLink> {
|
||||
const uri = `${gif.media_formats.gif.url}?hh=${gif.media_formats.gif.dims[1]}&ww=${gif.media_formats.gif.dims[0]}`
|
||||
const gifUrl = gif.media_formats.gif.url
|
||||
const params = new URLSearchParams()
|
||||
params.set('hh', String(gif.media_formats.gif.dims[1]))
|
||||
params.set('ww', String(gif.media_formats.gif.dims[0]))
|
||||
|
||||
// For Klipy GIFs, embed video format slugs so parseKlipyGif can
|
||||
// swap to the right format per platform at render time. Klipy uses
|
||||
// different filename slugs per format (unlike Tenor where format is
|
||||
// encoded in the URL ID), so this info must travel with the URL.
|
||||
try {
|
||||
const url = new URL(gifUrl)
|
||||
if (url.hostname === 'static.klipy.com') {
|
||||
const mp4Slug = getFileSlug(gif.media_formats.mp4?.url)
|
||||
const webmSlug = getFileSlug(gif.media_formats.webm?.url)
|
||||
if (mp4Slug) params.set('mp4', mp4Slug)
|
||||
if (webmSlug) params.set('webm', webmSlug)
|
||||
}
|
||||
} catch {}
|
||||
|
||||
const uri = `${gifUrl}?${params.toString()}`
|
||||
const altText = gif.content_description || gif.title
|
||||
return {
|
||||
type: 'external',
|
||||
uri,
|
||||
title: gif.content_description,
|
||||
description: createGIFDescription(gif.content_description),
|
||||
title: altText,
|
||||
description: createGIFDescription(altText),
|
||||
thumb: await imageToThumb(gif.media_formats.preview.url),
|
||||
}
|
||||
}
|
||||
|
||||
function getFileSlug(url: string | undefined): string | undefined {
|
||||
if (!url) return undefined
|
||||
const filename = url.split('/').pop()
|
||||
if (!filename) return undefined
|
||||
const dotIndex = filename.lastIndexOf('.')
|
||||
return dotIndex > 0 ? filename.slice(0, dotIndex) : undefined
|
||||
}
|
||||
|
||||
async function resolveExternal(
|
||||
agent: BskyAgent,
|
||||
uri: string,
|
||||
|
||||
Reference in New Issue
Block a user