fix: copy GIF URLs as text to preserve animation

PNG conversion strips GIF animation. GIFs are now detected by URL
pattern (.gif extension or Tenor/Klipy CDN) and copied as URL text
instead, so pasting back into chat re-renders the animated GIF.
This commit is contained in:
Jannis Braun
2026-03-25 03:28:00 +01:00
parent aeb4ea6e1d
commit c255b0066a
2 changed files with 38 additions and 5 deletions
@@ -83,6 +83,20 @@ describe('copyImageToClipboard', () => {
expect(clipboardItem).toBeInstanceOf(ClipboardItem);
});
it('copies GIF URLs as text to preserve animation', async () => {
const mockWriteText = vi.fn().mockResolvedValue(undefined);
Object.assign(navigator, {
clipboard: { write: vi.fn(), writeText: mockWriteText },
});
const mockAddToast = vi.fn();
vi.mocked(useUIStore.getState).mockReturnValue({ addToast: mockAddToast } as any);
await copyImageToClipboard('https://media.tenor.com/abc/tenor.gif');
expect(mockWriteText).toHaveBeenCalledWith('https://media.tenor.com/abc/tenor.gif');
expect(mockAddToast).toHaveBeenCalledWith('Copied GIF link', 'success', 3000);
});
it('falls back to copying URL as text on failure and shows toast', async () => {
vi.spyOn(globalThis, 'fetch').mockRejectedValue(new TypeError('CORS'));
const mockWriteText = vi.fn().mockResolvedValue(undefined);