Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Ignore image responses on non-200 status (#3693)

* Ignore image responses on non-200 status

* Fix tests

authored by

dan and committed by
GitHub
90c3ec87 15055cb8

+38 -7
+27 -2
__tests__/lib/images.test.ts
··· 1 + import ImageResizer from '@bam.tech/react-native-image-resizer' 2 + import RNFetchBlob from 'rn-fetch-blob' 3 + 1 4 import { 2 5 downloadAndResize, 3 6 DownloadAndResizeOpts, 4 7 } from '../../src/lib/media/manip' 5 - import ImageResizer from '@bam.tech/react-native-image-resizer' 6 - import RNFetchBlob from 'rn-fetch-blob' 7 8 8 9 describe('downloadAndResize', () => { 9 10 const errorSpy = jest.spyOn(global.console, 'error') ··· 30 31 const mockedFetch = RNFetchBlob.fetch as jest.Mock 31 32 mockedFetch.mockResolvedValueOnce({ 32 33 path: jest.fn().mockReturnValue('file://downloaded-image.jpg'), 34 + info: jest.fn().mockReturnValue({status: 200}), 33 35 flush: jest.fn(), 34 36 }) 35 37 ··· 84 86 const mockedFetch = RNFetchBlob.fetch as jest.Mock 85 87 mockedFetch.mockResolvedValueOnce({ 86 88 path: jest.fn().mockReturnValue('file://downloaded-image'), 89 + info: jest.fn().mockReturnValue({status: 200}), 87 90 flush: jest.fn(), 88 91 }) 89 92 ··· 117 120 undefined, 118 121 {mode: 'cover'}, 119 122 ) 123 + }) 124 + 125 + it('should return undefined for non-200 response', async () => { 126 + const mockedFetch = RNFetchBlob.fetch as jest.Mock 127 + mockedFetch.mockResolvedValueOnce({ 128 + path: jest.fn().mockReturnValue('file://downloaded-image'), 129 + info: jest.fn().mockReturnValue({status: 400}), 130 + flush: jest.fn(), 131 + }) 132 + 133 + const opts: DownloadAndResizeOpts = { 134 + uri: 'https://example.com/image', 135 + width: 100, 136 + height: 100, 137 + maxSize: 500000, 138 + mode: 'cover', 139 + timeout: 10000, 140 + } 141 + 142 + const result = await downloadAndResize(opts) 143 + expect(errorSpy).not.toHaveBeenCalled() 144 + expect(result).toBeUndefined() 120 145 }) 121 146 })
+11 -5
src/lib/media/manip.ts
··· 1 - import RNFetchBlob from 'rn-fetch-blob' 2 - import ImageResizer from '@bam.tech/react-native-image-resizer' 3 1 import {Image as RNImage, Share as RNShare} from 'react-native' 4 - import {Image} from 'react-native-image-crop-picker' 5 2 import * as RNFS from 'react-native-fs' 3 + import {Image} from 'react-native-image-crop-picker' 6 4 import uuid from 'react-native-uuid' 5 + import * as MediaLibrary from 'expo-media-library' 7 6 import * as Sharing from 'expo-sharing' 8 - import * as MediaLibrary from 'expo-media-library' 7 + import ImageResizer from '@bam.tech/react-native-image-resizer' 8 + import RNFetchBlob from 'rn-fetch-blob' 9 + 10 + import {isAndroid, isIOS} from 'platform/detection' 9 11 import {Dimensions} from './types' 10 - import {isAndroid, isIOS} from 'platform/detection' 11 12 12 13 export async function compressIfNeeded( 13 14 img: Image, ··· 62 63 const to1 = setTimeout(() => downloadResPromise.cancel(), opts.timeout) 63 64 downloadRes = await downloadResPromise 64 65 clearTimeout(to1) 66 + 67 + const status = downloadRes.info().status 68 + if (status !== 200) { 69 + return 70 + } 65 71 66 72 let localUri = downloadRes.path() 67 73 if (!localUri.startsWith('file://')) {