Bluesky app fork with some witchin' additions 💫 witchsky.app
bluesky fork client

feat: use t.gifs cdn for tenor search results (#8574)

authored by hailey.at and committed by

GitHub 806d3792 5e20d5ff

+34 -4
+16
__tests__/lib/string.test.ts
··· 6 6 createStarterPackLinkFromAndroidReferrer, 7 7 parseStarterPackUri, 8 8 } from '#/lib/strings/starter-pack' 9 + import {tenorUrlToBskyGifUrl} from '#/state/queries/tenor' 9 10 import {cleanError} from '../../src/lib/strings/errors' 10 11 import {createFullHandle, makeValidHandle} from '../../src/lib/strings/handles' 11 12 import {enforceLen} from '../../src/lib/strings/helpers' ··· 997 998 expect(createStarterPackGooglePlayUri(undefined, 'rkey')).toEqual(null) 998 999 }) 999 1000 }) 1001 + 1002 + describe('tenorUrlToBskyGifUrl', () => { 1003 + const inputs = [ 1004 + 'https://media.tenor.com/someID_AAAAC/someName.gif', 1005 + 'https://media.tenor.com/someID/someName.gif', 1006 + ] 1007 + 1008 + it.each(inputs)( 1009 + 'returns url with t.gifs.bsky.app as hostname for input url', 1010 + input => { 1011 + const out = tenorUrlToBskyGifUrl(input) 1012 + expect(out.startsWith('https://t.gifs.bsky.app/')).toEqual(true) 1013 + }, 1014 + ) 1015 + })
+5 -4
src/components/dialogs/GifSelect.tsx
··· 5 5 useRef, 6 6 useState, 7 7 } from 'react' 8 - import {TextInput, View} from 'react-native' 8 + import {type TextInput, View} from 'react-native' 9 9 import {useWindowDimensions} from 'react-native' 10 10 import {Image} from 'expo-image' 11 11 import {msg, Trans} from '@lingui/macro' ··· 15 15 import {cleanError} from '#/lib/strings/errors' 16 16 import {isWeb} from '#/platform/detection' 17 17 import { 18 - Gif, 18 + type Gif, 19 + tenorUrlToBskyGifUrl, 19 20 useFeaturedGifsQuery, 20 21 useGifSearchQuery, 21 22 } from '#/state/queries/tenor' 22 23 import {ErrorScreen} from '#/view/com/util/error/ErrorScreen' 23 24 import {ErrorBoundary} from '#/view/com/util/ErrorBoundary' 24 - import {ListMethods} from '#/view/com/util/List' 25 + import {type ListMethods} from '#/view/com/util/List' 25 26 import {atoms as a, ios, native, useBreakpoints, useTheme, web} from '#/alf' 26 27 import {Button, ButtonIcon, ButtonText} from '#/components/Button' 27 28 import * as Dialog from '#/components/Dialog' ··· 316 317 t.atoms.bg_contrast_25, 317 318 ]} 318 319 source={{ 319 - uri: gif.media_formats.tinygif.url, 320 + uri: tenorUrlToBskyGifUrl(gif.media_formats.tinygif.url), 320 321 }} 321 322 contentFit="cover" 322 323 accessibilityLabel={gif.title}
+13
src/state/queries/tenor.ts
··· 3 3 import {keepPreviousData, useInfiniteQuery} from '@tanstack/react-query' 4 4 5 5 import {GIF_FEATURED, GIF_SEARCH} from '#/lib/constants' 6 + import {logger} from '#/logger' 6 7 7 8 export const RQKEY_ROOT = 'gif-service' 8 9 export const RQKEY_FEATURED = [RQKEY_ROOT, 'featured'] ··· 84 85 } 85 86 return res.json() 86 87 } 88 + } 89 + 90 + export function tenorUrlToBskyGifUrl(tenorUrl: string) { 91 + let url 92 + try { 93 + url = new URL(tenorUrl) 94 + } catch (e) { 95 + logger.debug('invalid url passed to tenorUrlToBskyGifUrl()') 96 + return '' 97 + } 98 + url.hostname = 't.gifs.bsky.app' 99 + return url.href 87 100 } 88 101 89 102 export type Gif = {