From a97744d600c589ad44da2d0d1cda71c96913fce7 Mon Sep 17 00:00:00 2001 From: vineyardbovines Date: Tue, 14 Apr 2026 15:02:27 -0400 Subject: [PATCH] fix(gif): align Klipy response parsing with actual API shape The Klipy proxy returns Tenor-compatible responses (results array of Gif objects), not the custom shape (data array of KlipyGif objects) that was speculatively typed. Remove the dead normalizeKlipyGif function and associated types, and read body.results directly. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/state/queries/klipy.ts | 72 ++------------------------------------ 1 file changed, 2 insertions(+), 70 deletions(-) diff --git a/src/state/queries/klipy.ts b/src/state/queries/klipy.ts index 85c4b7dae4..f482bf8632 100644 --- a/src/state/queries/klipy.ts +++ b/src/state/queries/klipy.ts @@ -81,10 +81,10 @@ function createKlipyApi( if (!res.ok) { throw new Error('Failed to fetch KLIPY API') } - const body: KlipyResponse = await res.json() + const body: {next: string; results: Gif[]} = await res.json() return { next: body.next, - results: body.data.map(normalizeKlipyGif), + results: body.results, } } } @@ -103,71 +103,3 @@ export function klipyStaticUrl(gifUrl: string) { return '' } } - -/** - * Maps a native KLIPY gif object onto the Tenor-shaped `Gif` type so - * downstream consumers (resolveGif, composer drafts, ExternalEmbed, etc.) - * continue to work unchanged. - */ -function normalizeKlipyGif(k: KlipyGif): Gif { - const toMediaObject = (v: KlipyFileVariant) => ({ - url: v.url, - dims: [v.width, v.height] as [number, number], - duration: 0, - size: 0, - }) - - return { - id: k.slug, - title: k.title ?? '', - content_description: k.content_description ?? k.title ?? '', - tags: k.tags ?? [], - media_formats: { - gif: toMediaObject(k.file.hd.gif), - tinygif: toMediaObject(k.file.sm.gif), - preview: toMediaObject(k.file.sm.gif), - }, - // Tenor-only fields; stub sensibly for KLIPY. - created: 0, - hasaudio: false, - hascaption: false, - flags: '', - itemurl: k.url ?? '', - url: k.url ?? '', - } -} - -type KlipyFileVariant = { - url: string - width: number - height: number -} - -type KlipyFileFormats = { - gif: KlipyFileVariant - webp?: KlipyFileVariant - mp4?: KlipyFileVariant -} - -type KlipyFile = { - /** Small/thumbnail size, used in the picker grid */ - sm: KlipyFileFormats - /** Medium size */ - md: KlipyFileFormats - /** Full/large size, used when posting */ - hd: KlipyFileFormats -} - -type KlipyGif = { - slug: string - title?: string - content_description?: string - tags?: string[] - url?: string - file: KlipyFile -} - -type KlipyResponse = { - next: string - data: KlipyGif[] -}